1

Magento by default provide adding attribute to the products but not to the category.Is there any way to add attribute to the category? I would like to have attribute with input type- multiple select .

My question is explained in 2 parts.

Detail eg:

Part 1: I have a player(category) called XYZ and it should have attribute like team name. When i say multiple select it means,player can be part of different teams.So i will select lets say 3 team names.

so

  • player XYZ belongs to team A,B,C
  • player ABC belongs to team A,B
  • player PQR belongs to team B,C

Part 2: Now i want to include this teams A,B,C in the menu(frontend) and

  • when i select team A -> it will display all players who have team A (attribute) selected
  • Same for B,C.

Thank you

1

This sounds like your players should be products and your teams the categories. Then you can assign the products/players to multiple categories/teams.

That said, to more directly answer your question, here's an Inchoo Article detailing how to add attributes to categories, hopefully you can use it as a starting point if you want/need to go that route.

Copying from the article in case it goes missing later:

SQL setup script:

    $installer = $this;
$installer->startSetup();
$entityTypeId     = $installer->getEntityTypeId('catalog_category');
$attributeSetId   = $installer->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $installer->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$installer->addAttribute('catalog_category', 'new_cat_attrb',  array(
    'type'     => 'int',
    'label'    => 'New Category Attribute',
    'input'    => 'text',
    'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'visible'           => true,
    'required'          => false,
    'user_defined'      => false,
    'default'           => 0
));
$installer->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'new_cat_attrb',
    '11'                    //last Magento's attribute position in General tab is 10
);
$attributeId = $installer->getAttributeId($entityTypeId, 'new_cat_attrb');
$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 will set data of your custom attribute for root category
Mage::getModel('catalog/category')
    ->load(1)
    ->setImportedCatId(0)
    ->setInitialSetupFlag(true)
    ->save();
//this will set data of your custom attribute for default category
Mage::getModel('catalog/category')
    ->load(2)
    ->setImportedCatId(0)
    ->setInitialSetupFlag(true)
    ->save();
$installer->endSetup();

And the config.xml:

<resources>
    <new_attribute_csv_setup>
      <setup>
        <module>New_Attribute</module>
        <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
      </setup>
      <connection>
        <use>core_setup</use>
      </connection>
    </new_attribute_setup>
    <new_attribute_setup_write>
      <connection>
        <use>core_write</use>
      </connection>
    </new_attribute_setup_write>
    <new_attribute_setup_read>
      <connection>
        <use>core_read</use>
      </connection>
    </new_attribute_setup_read>
</resources>
  • :i am explaining the exact scenario: WE have football tshirt (final product to sell) This tshirt is associated with some players Called B. Now player B is a part of different club say club A,Club B,Club C. Now in top menu i want to include different Club Names. So when user select Club A , all players under club A will be displayed and when any particular player is selected ,all products associated with that players will be shown. So now how what is preferable ? – Vishal May 29 '14 at 15:00
  • 1
    Well how I would personally handle that is still make players "products" in the store. Obviously you're not selling the players, so you'll need some kind of custom attribute like for_sale (default: yes) set to 'no' on players. Update your .phtml files to only display the "Add to Cart"/Quantity sections if the product is for sale. Then you could add your t-shirts/merchandise as Related Products and display the related products block wherever you wish. – Don May 29 '14 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.