How to update subtotal after changing price with observer

0

I am using observer to change bundle product price. I have tried events ‘checkout_cart_product_add_after’ and ‘checkout_cart_save_after’. Both events update product’s price but subtotal remains same. In my case Price is 50 and Subtotal is 18.

Observer code (checkout_cart_save_after):

public function apply_customprice(Varien_Event_Observer $observer)
{

    $quote= $observer->getCart()->getQuote();
    foreach ($quote->getAllItems() as $bundleitems) {
        $parentProductId = $bundleitems->getProduct()->getId();
        if($bundleitems->getProduct()->getTypeId() == 'bundle')
        {
            $storeId = Mage::app()->getStore()->getStoreId();
            $Custom_price= 50;
            $item = Mage::getModel('sales/quote_item')->load($bundleitems->getId());
            $product_id = $item->getProductId();
            $product = Mage::getModel('catalog/product')->load($product_id);
            $item->setStoreId($storeId);
            $item->setCustomPrice($Custom_price);
            $item->setOriginalCustomPrice($Custom_price);
            $item->setProduct($product);
            $item->save();

            //for updating the totals
            $quote = Mage::getModel('checkout/session')->getQuote();
            $quote->collectTotals()->save();
        }

    }

}

Link: How to update subtotal after changing price with observer
Source: Stack Magento

Share.

About Author

Leave A Reply