Create new custom category attribute in Magento
There is no option in magento to add new custom category attribute. So if you want to add new category attribute in your magento you need to make some kind of code. Adding new custom attribute in magento using short code as following is short but not much more secure and proper way.
If you want to create new category attribute in proper way via module you can check my post
Adding Custom Category Attributes to Magento via Module
Copy and paste the following code in your header.phtml
require_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(
'type' => 'int',
'label'=> 'Your attribute label',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => "",
'group' => "General Information"
);
$installer->addAttribute('catalog_category', 'your_attribute_code', $attribute);
$installer->endSetup();
Run your site once. After that remove this code from header.phtml
Your attribute is created.
its appear in your catalog->manage categories->General information tab
Please support us, Like us on Facebook.
Subscribe to:
Post Comments (Atom)
I am not getting "your_attribute_code" value in the following function,
ReplyDeleteMage::getModel('catalog/category')->load(66);
I want to get the value
You can get the value of custom category attribute in category/view.phtml as
Delete$_category->get"your_attribute_code"();
This worked great, thanks :)
ReplyDeleteWould you provide information on how to install this as a real module in Magento? That would be great and less "hacky" :)
You can create a new module to create new category attribute.
DeleteAdding Custom Category Attributes to Magento via Module
i will try this one,Thanks for sharing.
ReplyDeleteMagento Developers
This is excellent one!! It works. :)
ReplyDeleteHi, can you help me to remove custom attr :) because I created two identical attribute
ReplyDelete