I'm trying to get a custom attribute from every product on the shopping cart to disable a shipping method if the attribute is set to Yes on any added product.
It doesn't work for configurable products (It gets the attribute for the parent). I tested it on simple and grouped ones and it works.
Basically I don't know how to look for the attribute on the child product.
Here's my model:
class Si_Shipping_Model_Shipping extends Mage_Shipping_Model_Shipping
{
public function collectCarrierRates($carrierCode, $request)
{
if (!$this->_checkCarrierAvailability($carrierCode, $request)) {
return $this;
}
return parent::collectCarrierRates($carrierCode, $request);
}
protected function _checkCarrierAvailability($carrierCode, $request = null)
{
foreach (Mage::getSingleton('checkout/cart')->getQuote()->getAllVisibleItems() as $item)
{
if($item->getProduct()->isConfigurable()){
// Do something to get the overweight attribute value
}else{
if($item->getProduct()->getOverweight()){
if($carrierCode == 'flatrate'){
return false;
}
}
}
}
return true;
}
}
config.xml
<global>
<helpers>
<shipping>
<class>Si_Shipping_Helper</class>
</shipping>
</helpers>
<models>
<shipping>
<rewrite>
<shipping>Si_Shipping_Model_Shipping</shipping>
</rewrite>
</shipping>
</models>
<sales>
<quote>
<item>
<product_attributes>
<overweight />
</product_attributes>
</item>
</quote>
</sales>