我试图在模块升级脚本中以编程方式添加自定义属性。该脚本可以正常运行并创建新属性(即,脚本运行后,它会出现在Magento管理列表中的目录->属性->管理属性下)。

最初,我使用的是Mage_Eav_Model_Entity_Setup类(建议使用here,并且未按预期设置“visible”或“apply_to”字段(“visible”始终为false,而“apply-to”始终保留为“所有产品类型”,而不是使用脚本中提供的列表)。

然后我找到了this,这说明我应该改用Mage_Catalog_Model_Resource_Setup,并且已经解决了“apply_to”的问题。

但是我仍然无法将属性的“visible”属性设置为true。如果有人对为什么仍未设置“可见”属性有任何想法,我将不胜感激,谢谢!

这是我的升级脚本代码:

$updater = $this;      // $this is class Mage_Eav_Model_Entity_Setup
$updater->startSetup();
$updater->addAttribute('catalog_product', 'my_test_attribute', array(
    'label'             => 'My Test Attribute',
    'type'              => 'int',
    'input'             => 'select',
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'apply_to'          => 'simple,configurable',
    'group'             => 'General',
    'visible'           => true,
    'required'          => true,
    'user_defined'      => true,
));
$updater->endSetup();

我在Windows 7的WAMP中运行Magento 1.7.0.1。

最佳答案

我现在已经解决了这个问题-它需要设置的也是“visible_on_front”属性,而不仅仅是“visible”属性。即我在上面的脚本中添加了这一行,它现在可以工作:

'visible_on_front'  => true,

10-04 12:10
查看更多