如何将自定义产品属性加载到报价项中?

i.a*_*els 2 magento

我正在为Magento开发一种定制的运输方式.对于此送货方式,我需要设置自定义产品属性(airfreight_allowed).送货方法检查所有产品的自定义属性是否设置为true.

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

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

在发货模块中,我访问这样的报价项:

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

但报价项目不包含airfreight_allowed属性.如何将airfreight_allowed属性添加到报价项?如何确保此属性包含相应产品属性的值?

i.a*_*els 10

将其添加到模块的config.xml中:

<global>
  <sales>
     <quote>
        <item>
            <product_attributes>
                <airfreight_allowed />
            </product_attributes>
        </item>
    </quote>
  </sales>
</global>
Run Code Online (Sandbox Code Playgroud)

将属性的属性"在产品列表中使用"设置为true.

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

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