I have simple products in Magento 1.9 that I can combine ship and would like to change the total shipping weight at checkout (and in shopping cart view for shipping estimate calculation etc) based on sku. For example, if one or two widgets with the correct sku are purchased, their weight is 1 lbs combined. If three to five widgets with the correct sku are purchased, their weight is 2 lbs combined etc. Tablerates could handle this if all items were included. However, I must limit it to certain items determined by sku.
The following code is triggered by the sales_quote_collect_totals_after event.
<?php class Weight_Extension_Model_Observer { public function adjustTotalWeight($observer) { $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems(); $combinedItems = 0; foreach($items as $item) { if($item->getSku() == 1 || $item->getSku() == 2) { $combinedItems++; } } if($combinedItems > 0 && $combinedItems < 3) $weight = 1; if($combinedItems >= 3 && $combinedItems < 6) $weight = 2; //send new $weight to Magento and persist through checkout? } }
How do I ensure the new calculated weight is used and am I observing the correct event?
This is solved.
How did you solve it?
It is unfair to ask for help, find your own solution and don't post it. People will remember you and wont help you anymore.