cancel
Showing results for 
Search instead for 
Did you mean: 

Manipulate weight on checkout

Manipulate weight on checkout

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?

3 REPLIES 3

Re: Manipulate weight on checkout

This is solved.

Re: Manipulate weight on checkout

How did you solve it?

Re: Manipulate weight on checkout

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.