【问题标题】:Magento - Assign option to multiselect attribute programmaticallyMagento - 以编程方式将选项分配给多选属性
【发布时间】:2012-06-21 08:18:03
【问题描述】:

我有一个多选类型的自定义属性,我想以编程方式为其分配值,但它不像“文本字段”属性那样工作。

目前,我使用 Magento 的 SOAP API 中的 product.update 来更新附加属性。

我已经尝试过搜索并尝试过,但不幸的是它们似乎没有用。我认为这应该默认正常工作,我们需要一些技巧吗?

magento 有没有关于这类工作的官方文件?

【问题讨论】:

    标签: php magento attributes entity-attribute-value


    【解决方案1】:

    可以编写一个设置脚本来为多选属性添加值。考虑到您的属性是颜色,并且您尝试将值 'Red','Green','Blue' 添加到属性中,然后像这样添加

    $oInstaller = new Mage_Eav_Model_Entity_Setup('core_setup');
    $iAttribId = $oInstaller->getAttributeId('catalog_product', 'color');
    $oInstaller->addAttributeOption(array(
            'attribute_id' => $iAttribId, 
            'value' => array(
                array(
                    0 => 'Red',
                    1 => 'Blue',
                    2=> 'Green'
                )
            ),
        ));
    

    希望这行得通。

    【讨论】:

    • 问题是属性选项已创建,我想将它们分配给当前产品。
    • 您的意思是您创建了一个具有一些值的多选属性,并试图以编程方式而不是通过通常的 Magento Admin->Manage Products 更新来更新具有相同属性的某些值的特定产品?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多