Skip to content

Magento 1.9 – Custom product attribute

I’m trying to create 3 custom attributes for every product but somehow these attributes are not created even after I deleted the cache logged out from admin and logged in again. I have to do something else? Thank you!

  • app/etc/modules/Store_ProductCustomAttribute.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Store_ProductCustomAttribute>
            <active>true</active>
            <codePool>local</codePool>
        </Store_ProductCustomAttribute>
    </modules>
</config> 

-app/code/local/Store/ProductCustomAttribute/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Store_ProductCustomAttribute>
            <version>0.1.0</version>
        </Store_ProductCustomAttribute>
    </modules>
    <global>
        <resources>
            <store_productcustomattribute_setup>
              <setup>
                   <module>Store_ProductCustomAttribute</module>
                   <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
              </setup>
          </store_productcustomattribute_setup>
        </resources>  
    </global>
</config> 

-app/code/local/Store/ProductCustomAttribute/sql/store_productcustomattribute_setup/mysql4-install-0.1.0.php

<?php

$installer = $this;
$installer->startSetup();

$installer->addAttribute('catalog_product', 'width', array(
    'group'           => 'General',
    'label'           => 'Width',
    'input'           => 'text',
    'type'            => 'varchar',
    'sort_order'      => 50,
    'frontend'        => '',
    'frontend_model'  => '',
    'class'           => '',
    'visible'         => 1,
    'default'         => '',
    'unique'          => 0,
    'required'        => 0,
    'visible_on_front'=> 0,
    'filterable'      => 0,
    'searchable'      => 0,
    'comparable'      => 0,
    'user_defined'    => 1,
    'is_configurable' => 0,
    'global'          => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'apply_to'          => Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL,
    'note'            => '',
));

$installer->addAttribute('catalog_product', 'height', array(
    'group'           => 'General',
    'label'           => 'Height',
    'input'           => 'text',
    'type'            => 'varchar',
    'sort_order'      => 50,
    'frontend'        => '',
    'frontend_model'  => '',
    'class'           => '',
    'visible'         => 1,
    'default'         => '',
    'unique'          => 0,
    'required'        => 0,
    'visible_on_front'=> 0,
    'filterable'      => 0,
    'searchable'      => 0,
    'comparable'      => 0,
    'user_defined'    => 1,
    'is_configurable' => 0,
    'global'          => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'apply_to'          => Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL,
    'note'            => '',
));

$installer->addAttribute('catalog_product', 'depth', array(
    'group'           => 'General',
    'label'           => 'Depth',
    'input'           => 'text',
    'type'            => 'varchar',
    'sort_order'      => 50,
    'frontend'        => '',
    'frontend_model'  => '',
    'class'           => '',
    'visible'         => 1,
    'default'         => '',
    'unique'          => 0,
    'required'        => 0,
    'visible_on_front'=> 0,
    'filterable'      => 0,
    'searchable'      => 0,
    'comparable'      => 0,
    'user_defined'    => 1,
    'is_configurable' => 0,
    'global'          => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'apply_to'          => Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL,
    'note'            => '',
));

$installer->endSetup();

?>