Magento – What purpose have category attribute sets

attribute-setavs-fastsimpleimportcategory

Since Categories are EAV Models, they also have an attribute set. All categories, which are created from the admin panel get the default attribute set. This is set by the controller (\Mage_Adminhtml_Catalog_CategoryController::saveAction).

On the other side, when I create a category programatically and don't set the attribute set id, the id 0 is saved to the entity table. The category is shown in frontend and backend anyway and seems to have all attributes.

Also the import module Avs_Fastsimpleimport hardcodes the attribute set id to 0 in the category import (\AvS_FastSimpleImport_Model_Import_Entity_Category::_saveCategories).

It seems that the attribute set id of categories doesn't matter. So what purpose has this and should I set the attribute set id when I create categories programmatically?

Best Answer

Magento uses several eav entity types like product, category, order, quote, customer... They have same implementation on eav resource abstract class level, so they uses same tables (eav_attribute, eav_entity_attribute, eav_enetity_type, eav_attribute_set, eav_attribute_group ...) for persistence. But only product model has practical use of attribute sets for editing several product types with own attributes on backend. If you want to research further you can start at point protected function _getLoadAttributesSelect($object, $table) of the class Mage_Catalog_Model_Resource_Abstract.

I recommend to use same Magento approach saving and creating a category:

$category->setAttributeSetId($category->getDefaultAttributeSetId());

And this will preserve models from misbehaving