cancel
Showing results for 
Search instead for 
Did you mean: 

how to update custom price cart subtotal programmatically in magento

SOLVED

how to update custom price cart subtotal programmatically in magento

$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

lavlesh kumar shukla
2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: how to update custom price cart subtotal programmatically in magento

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();

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

View solution in original post

Re: how to update custom price cart subtotal programmatically in magento

Both Technique is not working for update subtotal amount

lavlesh kumar shukla

View solution in original post

3 REPLIES 3

Re: how to update custom price cart subtotal programmatically in magento

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();

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Re: how to update custom price cart subtotal programmatically in magento

Both Technique is not working for update subtotal amount

lavlesh kumar shukla

Re: how to update custom price cart subtotal programmatically in magento

Hi , Qaisar

your solution is fine for me . Thanks for your support
lavlesh kumar shukla