【问题标题】:Adding attributes to custom product only?仅向自定义产品添加属性?
【发布时间】:2012-08-21 08:52:39
【问题描述】:

这里是菜鸟。 我尝试向我的自定义产品 (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',
    ));

【问题讨论】:

  • 不可能,因为产品和定制产品是同一个东西,使用相同的型号。可能的是,控制 .phtml 将向产品或自定义产品显示的内容。
  • 您应该改用产品自定义选项。
  • 感谢 cmets,今天才发现它们 ;-) 那么有人可以指导我学习自定义选项的教程吗?

标签: magento attributes


【解决方案1】:

要回答我自己的问题,以下是答案: 我需要将属性添加到以下数组并重新运行 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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 2023-03-28
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    • 2016-07-16
    相关资源
    最近更新 更多