0

i have written a code to remove related services while removing a product from cart. Even though the product and its services are getting removed from quote_item table, the total price in Mage::getSingleton('checkout/cart') or Mage::getSingleton('checkout/session') isn't getting updated.

    foreach ( $quote->getItemsCollection() as $item ) {  
       if ($item->getSwType() == 'service' || $item->getDeliveryParentId()) {  
            $item->isDeleted(true);  
            $quote->removeItem($item->getItemId());  
        }  
    }
1

you have to call

$quote->collectTotals(); 

and possibly

$quote->setTotalsCollectedFlag(false)->collectTotals();

if quote is already collected. Be prepared tho as Magento is not expecting that this method is called multiple times and so do lot of 3rd party extensions who add something to totals. So you need to verify your totals as well if they are correct .

|improve this answer|||||
  • No i had tried this already. It dint work. – Anusha Aug 29 '13 at 9:40
  • i am deleting the product then removing the service items. If i place the removing items above deleting the product, it worked. But many other condition breaks and its not the right way. i suspect after calling deleteProduct() then removing the service is not getting updated – Anusha Aug 29 '13 at 9:42
  • @Anusha after calling collectTotals() did you call $quote->save()? – Marius Aug 29 '13 at 10:45
  • @Marius i did call $quote->save() after collectTotals(). But it dint give me correct total – Anusha Sep 3 '13 at 4:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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