I’m trying to setup attribute-sets and attributes automatically via a setup script. The script is working and all attributes are added to the sets, no problem with that… however, when I look at the attributes the visible_on_front, the used_in_product_listing and the global are not set properly. This is what I have:
$installer->addAttribute('catalog_product', '<attribute_code>', array(
'group' => 'General',
'input' => 'date',
'type' => 'datetime',
'label' => '<some_label>',
'backend' => 'eav/entity_attribute_backend_datetime',
'is_global' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE,
'is_visible_on_front' => 1,
'visible_on_front' => 1,
'used_in_product_listing' => 1,
));
Anyone know how I can fix this so it works?
The trick here is to make sure that you are using the correct Setup object. The default Setup object is
Mage_Eav_Model_Entity_Setupwhich will add your attribute intoeav_attributetable but it is not aware of the extra fields incatalog_eav_attributesuch asused_in_product_listing(orcustomer_eav_attributeand it’s fields for that matter).So, add this at the top of the install script:
That should make the difference.
FYI, you can use
Mage_Customer_Model_Entity_Setupto achieve the same end for customer attributes.