Magento模块设置/安装程序脚本

JND*_*PNT 5 installation magento

我正在尝试通过设置脚本自动设置属性集和属性.该脚本正在运行,并且所有属性都被添加到集合中,没有问题...但是,当我查看属性时visible_on_front,used_in_product_listing并且global未正确设置.这就是我所拥有的:

$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,
));
Run Code Online (Sandbox Code Playgroud)

任何人都知道如何解决这个问题,以便它有效吗?

Jon*_*Day 20

这里的技巧是确保您使用正确的安装对象.默认的Setup对象是Mage_Eav_Model_Entity_Setup将您的属性添加到eav_attribute表中,但它不知道catalog_eav_attribute诸如used_in_product_listing(或者customer_eav_attribute它的字段)之类的额外字段.

因此,请在安装脚本的顶部添加:

$installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
$installer->startSetup();
Run Code Online (Sandbox Code Playgroud)

这应该有所不同.

仅供参考,您可以使用Mage_Customer_Model_Entity_Setup来实现客户属性的同一目的.