Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

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


Magento create new custom category attribute

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.

  1. I am not getting "your_attribute_code" value in the following function,
    Mage::getModel('catalog/category')->load(66);
    I want to get the value

    ReplyDelete
    Replies
    1. You can get the value of custom category attribute in category/view.phtml as

      $_category->get"your_attribute_code"();

      Delete
  2. This worked great, thanks :)

    Would you provide information on how to install this as a real module in Magento? That would be great and less "hacky" :)

    ReplyDelete
  3. i will try this one,Thanks for sharing.


    Magento Developers

    ReplyDelete
  4. This is excellent one!! It works. :)

    ReplyDelete
  5. Hi, can you help me to remove custom attr :) because I created two identical attribute

    ReplyDelete

 

Copyright @ 2017 HKBlog.