首页 文章

Magento升级脚本创建的新属性的可见性

提问于
浏览
5

我试图在模块升级脚本中以编程方式添加自定义属性 . 脚本运行正常并创建新属性(即,一旦脚本运行,它将出现在Catalog-> Attributes-> Manage Attributes下的Magento管理列表中) .

起初我使用的是 Mage_Eav_Model_Entity_Setup 类(推荐here,并且'visible'和'apply_to'字段都没有按预期设置('visible'始终为false,'apply-to'保持为"All product types"而不是使用脚本中提供的列表) .

然后我找到了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 .

2 回答

  • 0

    我现在已经解决了这个问题 - 它需要的是“visible_on_front”属性,而不仅仅是“可见” . 即我将此行添加到上面的脚本中,它现在可以正常工作:

    'visible_on_front'  => true,
    
  • 1

    该属性不是布尔值,它是整数 . 所以你设置1 = true 0 = false;

相关问题