$aPost = Mage::app()->getFrontController()->getRequest()->getPost(); $id = $aPost['product']; $qty = $aPost['qty']; $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($id); $bundleType = $product->getTypeId(); if ($bundleType == 'bundle') { $collection = $product->getTypeInstance(true)->getSelectionsCollection($product->getTypeInstance(true)->getOptionsIds($product), $product); $itemIds = array(); $b=0; $n=1; foreach ($collection as $item) { if($n == 1) {$price = $item->getPrice();} $sku = $item->getSku(); if($sku = 'shoose01') { $b=20; } elseif ($sku = 'shoose01') { $b=30; } elseif ($sku = 'simple2122'){ $b=40; } elseif ($sku = 'moniteur24'){ $b=60; } else { $b=0; } $n++; } } $single_price = $price+$b; if($bundleType == 'bundle') { $item->setCustomPrice($single_price); $item->setOriginalCustomPrice($single_price); }
i am updating cart item price of bundle product in the time of add to cart , but sub total is not updating but Unit price and grand total is updating , please help me , what is the issue in my code
Solved! Go to Solution.
Try with $item->getProduct()->setIsSuperMode(true);
$item->setCustomPrice($single_price); $item->setOriginalCustomPrice($single_price); $item->getProduct()->setIsSuperMode(true);
//for updating the totals
$quote = Mage::getModel('checkout/session')->getQuote();
$quote->collectTotals()->save();
If first solution not work second solution is
$item= Mage::getModel('sales/quote_item')->load($item->getId()); $product_id = $item->getProductId(); $product=Mage::getModel('catalog/product')->load($product_id); $item->setStoreId(Mage::app()->getStore()->getStoreId()); $item->setCustomPrice($single_price); $item->setOriginalCustomPrice($single_price); $item->setProduct($product); $item->save();
//for updating the totals
$quote = Mage::getModel('checkout/session')->getQuote();
$quote->collectTotals()->save();
Both Technique is not working for update subtotal amount
Try with $item->getProduct()->setIsSuperMode(true);
$item->setCustomPrice($single_price); $item->setOriginalCustomPrice($single_price); $item->getProduct()->setIsSuperMode(true);
//for updating the totals
$quote = Mage::getModel('checkout/session')->getQuote();
$quote->collectTotals()->save();
If first solution not work second solution is
$item= Mage::getModel('sales/quote_item')->load($item->getId()); $product_id = $item->getProductId(); $product=Mage::getModel('catalog/product')->load($product_id); $item->setStoreId(Mage::app()->getStore()->getStoreId()); $item->setCustomPrice($single_price); $item->setOriginalCustomPrice($single_price); $item->setProduct($product); $item->save();
//for updating the totals
$quote = Mage::getModel('checkout/session')->getQuote();
$quote->collectTotals()->save();
Hi , Qaisar