Reputation: 7465
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?
Upvotes: 5
Views: 4398
Reputation: 18692
The trick here is to make sure that you are using the correct Setup object. The default Setup object is Mage_Eav_Model_Entity_Setup
which will add your attribute into eav_attribute
table but it is not aware of the extra fields in catalog_eav_attribute
such as used_in_product_listing
(or customer_eav_attribute
and it's fields for that matter).
So, add this at the top of the install script:
$installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
$installer->startSetup();
That should make the difference.
FYI, you can use Mage_Customer_Model_Entity_Setup
to achieve the same end for customer attributes.
Upvotes: 20