9

I am trying adding a extra category attrbiute to general infomation tab i have tried adding that using the following code ,

require_once("app/Mage.php"); Mage::app('default'); Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); $installer = new Mage_Eav_Model_Entity_Setup('core_setup'); $entityTypeId = $installer->getEntityTypeId('catalog_category'); $attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId); $attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId); $installer->addAttribute('catalog_category', 'nav_left', array( 'type' => 'tinyint', 'label' => 'Show in left navgigation', 'input' => 'boolean', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 'visible' => true, 'required' => false, 'user_defined' => false, 'default' => 0 )); $installer->addAttributeToGroup( $entityTypeId, $attributeSetId, $attributeGroupId, 'nav_left', '11' //last Magento's attribute position in General tab is 10 ); $attributeId = $installer->getAttributeId($entityTypeId, 'nav_left'); $installer->run(" INSERT INTO `{$installer->getTable('catalog_category_entity_int')}` (`entity_type_id`, `attribute_id`, `entity_id`, `value`) SELECT '{$entityTypeId}', '{$attributeId}', `entity_id`, '1' FROM `{$installer->getTable('catalog_category_entity')}`; "); 

This is just working fine but this is adding an additional information tab named General just to the right of general infomation tab i have tried adding it to first tab using attributeGroupId set to 4 but after testing it is just crashing the site.

Any idea how can i add that attribute to first tab.

3 Answers 3

6

Try it like this:

$installer->addAttribute('catalog_category', 'nav_left', array( 'group' => 'General Information', 'type' => 'int', 'label' => 'Show in left navgigation', 'input' => 'boolean', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 'visible' => true, 'required' => false, 'user_defined' => false, 'default' => 0 )); 

EDIT
$installer must be instance of Mage_Catalog_Model_Resource_Setup.

Off topic a bit: I recommend adding this script in an update file of one of your modules instead of making an instance of Mage::app() and running it 'on the fly'. If you put it in an upgrade script it's portable to other instances.

9
  • Thanks for your answer but after running this i am getting server error on the site. Commented May 29, 2013 at 9:18
  • what error are you getting? I edited the answer. Maybe that's the problem. Commented May 29, 2013 at 9:25
  • the logs files contanis nothing the report file is saying. "Base table or view not found: 1146 Table 'wwwinsta_Joyevincent.catalog_category_entity_tinyint' doesn't exist" Commented May 29, 2013 at 9:40
  • Okzz this worked adding date attr in general info tab but i m trying adding a yes/No type attr any idea for that ? Commented May 29, 2013 at 9:51
  • 2
    I think you should better make a post with all the question you have about this. There is no point in discussing it over someone else's question because it's a bit off topic. Commented May 29, 2013 at 10:28
5

I have managed it work in expected way like this.

$installer->addAttribute('catalog_category', 'left_nav', array( 'group' => 'General Information', 'type' => 'int', 'label' => 'Show in left navigation', 'input' => 'select', 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE, 'visible' => true, 'required' => false, 'user_defined' => false, 'default' => 0, 'source' => 'eav/entity_attribute_source_boolean' )); 

Thanks

0

You can custom yes/no attribute to category section using the following code.

$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'featured_product', array( 'group' => 'General Information', 'input' => 'select', 'type' => 'text', 'label' => 'Featured Product', 'backend' => '', 'visible' => true, 'required' => false, 'visible_on_front' => true, 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 'source' => 'eav/entity_attribute_source_boolean', 

));

Please refer my tutorial for step by step explanation and file structure. http://www.pearlbells.co.uk/add-custom-attribute-dropdown-category-section-magento/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.