1

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?

1

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:

Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product));

All you have to do in your observer is:

$quote_id = $this->getEvent()->getQuoteItem()->getQuote()->getId();
  • Please check my question I'm able to get quote_id in event checkout_cart_add_product_complete and want to set custom price for quote_item. and not able to get quote_id in event checkout_cart_product_add_after. – Vinaya Maheshwari Mar 2 '17 at 10:21
  • There is no reason why you cannot achieve the same thing in checkout_cart_product_add_after as you're doing in checkout_cart_add_product_complete. Just use $this->getEvent()->getQuoteItem()->getQuote() and do whatever you need with quote items. – Sinisa Nedeljkovic Mar 2 '17 at 10:24
  • 1
    please check this : magento.stackexchange.com/a/156952/14039. – Vinaya Maheshwari Mar 2 '17 at 10:25
  • I still think that your business logic can be defined on the other way. But, let's not go further with it, you can try to rewrite Mage_Checkout_Model_Cart, and in addProduct() function, just add new event dispatch before return $this;. Something like: Mage::dispatchEvent('checkout_cart_product_add_after_custom', array('quote' => $this->getQuote(), 'quote_item' => $result, 'product' => $product));. If there is no quote_id set, just add check and call save(), and live with that little overhead. – Sinisa Nedeljkovic Mar 2 '17 at 10:34
  • Please check my edit question. – Vinaya Maheshwari Mar 2 '17 at 12:49

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.