I want to add some free gift to cart , so I create an observer, the code is:
<?php
class Free_Checkout_Model_Observer
{
public function modifyPrice(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$quote = Mage::getModel('checkout/session')->getQuote();
$quote_item = $event->getQuoteItem();
$productId = $event->getQuoteItem()->getProduct()->getId();
$product = Mage::getModel('catalog/product')->load($productId);
$productData = $product->getData();
if($productData['gift']){
$new_price = 0;
$quote_item->setOriginalCustomPrice($new_price);
$quote_item->setCustomPrice($new_price);
$quote_item->save();
}
}
}
but when I add an item to cart , in the shopping cart, the subtotal is 0, is anyone tell me how to solve this issue? when I add one more item or refresh the shopping cart page, the subtotal is correct
Try
$quote->collectTotals()->save()
at the end of your function