2

We have two shipping methods: package and postal. Postal is the cheapest. We have shipping rules based on weight. One of our products is large sheets of paper, because this cannot be send as postal we gave this product a high weight. This works fine, when a large sheet of paper is ordered the package shipping method is selected.

Now we've added a custom option to the product, saying 'cut before sending'. When the customer selects it, we will cut the large sheet of paper in 4 and send it as postal. But how can we change the weight of the product when the 'please cut' option is selected? The package shipping method is still selected, but the postal method should be selected.

1 Answer 1

4

Paul,Magento have magic logic to change the weight of cart item.When magento is added a product in cart it fire an event sales_quote_item_set_product and it send two params one is Quote item(Quote Object) and another is Current Carted product object(Mage_Catalog_Model_Product)

See at Class Mage_Sales_Model_Quote_Item event

Mage::dispatchEvent('sales_quote_item_set_product', array(
    'product' => $product,
    'quote_item' => $this
));

I suggest to the trigger an event/observer on this occasion and you can change weight of quote items using setter function setWeight() and another thing is that magento is save quote item weight at sales_flat_quote_item Table at database.

Code of Observer:

<?php
class Stackexchange_Magento53367_Model_Observer
{
    public function setweightCustomOption(Varien_Event_Observer $observer)
    {
        $Event = $observer->getEvent();

        //Mage::dispatchEvent('sales_quote_item_set_product', array('product' => $product,'quote_item' => $this));
        $product=$Event->getProduct();
        $quote_item=$Event->getQuoteItem();
        $quote_item->setWeight(900);
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.