1

菜鸟在这里。我尝试向我的自定义产品 (customproduct) 添加一些属性,但它们最终也适用于所有产品。

我希望仅在我的自定义产品 (customproduct) 的常规选项卡下显示属性的组/选项卡(自定义设置)。谁能指导我正确的方式?

我的代码如下所示:(mysql4-install-0.1.0.php)

$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$setup->addAttribute('catalog_product', 'PartnerID', array(
        'group'         => 'Custom Settings',
        'input'         => 'text',
        'type'          => 'text',
        'label'         => 'Partner ID',
        'backend'       => '',
        'visible'       => 1,
        'required'      => 0,
        'user_defined' => 1,
        'searchable' => 0,
        'filterable' => 0,
        'comparable'    => 0,
        'visible_on_front' => 0,
        'visible_in_advanced_search'  => 0,
        'is_html_allowed_on_front' => 0,
        'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'apply_to'      => 'customproduct',
    ));
4

1 回答 1

2

要回答我自己的问题,答案如下:我需要将属性添加到以下数组并重新运行 installscript。(另外,我的新产品类型 customproduct 的配置有误)

$fieldList = array(
            'PartnerId'
                        ...
    );

    // make these attributes applicable to customproduct
    foreach ($fieldList as $field) {
        $applyTo = split(',', $installer->getAttribute('catalog_product', $field, 'apply_to'));
        if (!in_array('customproduct', $applyTo)) {
            $applyTo[] = 'customproduct';
            $installer->updateAttribute('catalog_product', $field, 'apply_to', join(',', $applyTo));
        }
    }

现在,新属性仅适用于 customproduct。

于 2012-08-28T06:59:50.017 回答