【问题标题】:How to load a custom product attribute into a quote item?如何将自定义产品属性加载到报价项目中?
【发布时间】:2012-04-22 10:39:32
【问题描述】:

我正在为 Magento 开发一种自定义运输方式。对于这种运输方式,我需要设置一个自定义产品属性 (airfreight_allowed)。 shipping 方法检查是否所有产品的自定义属性都设置为 true。

我已经使用安装脚本添加了产品属性:

$installer->addAttribute('catalog_product', 'airfreight_allowed', array(
'input'         => 'select',
'source'        => 'eav/entity_attribute_source_boolean'
...
));

在运输模块中,我访问这样的报价项目:

foreach ($request->getAllItems() as $item) {   /* Mage_Shipping_Model_Rate_request */
    if($item->getAirfreightAllowed() != 1)
        return false; /* Airfreight not allowed */
}

但报价单不包含 airfreight_allowed 属性。如何将 airfreight_allowed 属性添加到报价项目?以及如何确保该属性包含相应产品属性的值?

【问题讨论】:

    标签: magento


    【解决方案1】:

    将此添加到模块的 config.xml:

    <global>
      <sales>
         <quote>
            <item>
                <product_attributes>
                    <airfreight_allowed />
                </product_attributes>
            </item>
        </quote>
      </sales>
    </global>
    

    将属性的“用于产品列表”的属性设置为 true。

    然后你可以像这样访问属性:

    foreach ($request->getAllItems() as $item) {   
        if($item->getProduct()->getAirfreightAllowed() != 1)
            return false;
    }
    

    【讨论】:

    • 任何人都可以帮助在 Magento 2 中设置上述内容吗?
    猜你喜欢
    • 1970-01-01
    • 2012-06-10
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 2014-07-29
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多