I have two event observer in my custom module :
// 1st : checkout_cart_product_add_after
$item = $observer->getQuoteItem();
$item->setIsNew(true);
// 2nd : checkout_cart_add_product_complete
$quote = Mage::getSingleton('checkout/cart')->getQuote();
$quote_id = $quote->getId(); // quote_id
foreach($quote->getAllItems() as $quote_item)
{
if($quote_item->getIsNew() == true)
{
$item = $quote_item;
}
}
// here I want to set custom quote item price and tried below code but it is not working
$item->setCustomPrice($current_tour_price);
$item->setOriginalCustomPrice($current_tour_price);
$item->getProduct()->setIsSuperMode(true);
$item->save(); // updated
I want to set custom price to quote item in checkout_cart_add_product_complete
event.
If I am using the code setCustomPrice
and setOriginalCustomPrice
in checkout_cart_product_add_after
event then it is working.
But I need quote_id
as well with dynamic price for some other use and I can't get quote_id
in checkout_cart_product_add_after
event, so I am using checkout_cart_add_product_complete
event.
How to set quote item custom price in event checkout_cart_add_product_complete
?
EDIT :
With $item->save()
it save custom price for quote_item but on change currency custom price not going to update.
I also tried https://stackoverflow.com/a/38243913/4073217 but it is not working in my case.
How to set custom price for quote_item which work with currency change?
Best Answer
You can always update quote, hack it, change value directly in database, but it would be overkill and so far from best practice.
If you need quote_id, you can easily grab it from
checkout_card_product_add_after
event, because it set quote_item during event dispatch:All you have to do in your observer is: