Install / install Magento script module

I am trying to configure attributes and attributes automatically using a setup script. The script works and all attributes are added to the sets, no problem with this ... however, when I look at the attributes visible_on_front, used_in_product_listingand are globalset incorrectly. 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,
));

Does anyone know how I can fix this to make it work?

+5
source share
1 answer

The trick here is to make sure that you are using the correct installation object. The default installation object is Mage_Eav_Model_Entity_Setupone that will add your attribute to the table eav_attribute, but it does not know about additional fields in catalog_eav_attribute, such as used_in_product_listing(or customer_eav_attributein this case, fields).

, script:

$installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
$installer->startSetup();

.

FYI, Mage_Customer_Model_Entity_Setup .

+19

All Articles