Creating custom category attribute in Magento

In this short article contains code for creating custom category attribute in Magento . Run this script from your magento root folder and it will create custom attribute of type int in General group. To test whether attribute is created or not Go to your magento admin panel > catelog > manage categories and user General tab you will see Most Popular Products attribute.

<?phprequire_once('app/Mage.php');Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));$installer = new Mage_Sales_Model_Mysql4_Setup;$attribute  = array(    'group'    => 'General',    'type'     => 'int',    'label'    => 'Most Popular Products',    'input'    => 'select',    'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,    'visible'           => true,    'required'          => false,    'user_defined'      => true,    'default'           => 0,    'source' => 'eav/entity_attribute_source_boolean');$installer->addAttribute('catalog_category', 'most_popular_products', $attribute);$installer->endSetup();//Following is code for removing already created custom category attribute//$installer = new Mage_Sales_Model_Mysql4_Setup;//$installer->removeAttribute('catalog_category', 'most_popular_products');?>



Popular posts from this blog

MATLAB code for Circular Convolution using Matrix method

Positive number pipe in angular 2+