I have 4 main products in cart, Each item is having different price. I want to update cart's total price as $40 without considering each line item price. I want to show $40 as combined price for all 4 items.
I tried with below code, but this can update each line item price.
<events>
<sales_quote_add_item>
<observers>
<Company_Module_Model_Observer>
<type>singleton</type>
<class>Company_Module_Model_Observer</class>
<method>updatePrice</method>
</Company_Module_Model_Observer>
</observers>
</sales_quote_add_item>
</events>
<?php
class Company_Module_Model_Observer
{
public function getNewPrice()
{
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
$custom_price = 40;
foreach ($cartItems as $item) {
$productId = $item->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
$actualPrice = $product->getPrice();
$newprice = $custom_price;
}
return $newprice;
}
public function updatePrice($observer)
{
$event = $observer->getEvent();
$product = $event->getProduct();
$quote_item = $event->getQuoteItem();
$new_price = $this->getNewPrice();
$quote_item->setOriginalCustomPrice($new_price);
//$quote_item->save();
$quote_item->getQuote()->save();
//Mage::getSingleton('checkout/cart')->save();
}
}