I’m developing a custom shipping method for Magento. For this shipping method I need to set a custom product attribute (airfreight_allowed). The shipping method checks whether the custom attribute is set to true for all products.
I have added the product attribute with an install script:
$installer->addAttribute('catalog_product', 'airfreight_allowed', array(
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean'
...
));
In the shipping module I access the quote items like this:
foreach ($request->getAllItems() as $item) { /* Mage_Shipping_Model_Rate_request */
if($item->getAirfreightAllowed() != 1)
return false; /* Airfreight not allowed */
}
But the quote item doesn’t contain the airfreight_allowed attribute. How can I add the airfreight_allowed attribute to the quote item? And how do I make sure this attribute contains the value of the corresponding product attribute?
Add this to your module’s config.xml:
Set the attribute’s property “used in product listing” to true.
Then you can access the attribute like this: