I have work on the task in which I need to handle quote item, here I have use two event



here it work fine, But when I have change Quantity directly in mini cart then my Logic was not work. For this I am find some event which work for me. If You have any solution this Pleas Provide Me

my code is

<event name="checkout_cart_add_product_complete">
    <observer name="customprice" instance="Ns\Module\Observer\CustomPrice" />
<event name="checkout_cart_update_item_complete">
    <observer name="custompriceupdate" instance="Ns\Module\Observer\CustomPrice" />
<event name="sales_quote_item_qty_set_after">
    <observer name="custompriceupdateqty" instance="Ns\Module\Observer\CustomPrice" />

and observer is

public function execute(\Magento\Framework\Event\Observer $observer)
    $cart = $this->cart;
    $quote = $cart->getQuote();
    $items = $cart->getQuote()->getAllItems();
    $basetotal = 0;
    foreach ($items as $itemforprice) {
        $total = $this->processItem($itemforprice);
        $basetotal += $total;


private function processItem($itemforprice)
    $myprice = 100;
    $total = $myprice * $qty;




    return $total;

1 Answer 1


Use sales_quote_item_qty_set_after which will fire when Qty is update.

 $this->_eventManager->dispatch('sales_quote_item_qty_set_after', ['item' => $this]);

I guess that you want to update cart item price.

sales_quote_item_qty_set_after event provide quote item as it parameter.So you don't need to inject cart object $this->cart here. Also, don't need to save the quote and calculate the subtotal, as Magento automatically do that during firing on this event.


namespace Ns\Module\Observer;

class CustomPriceSet  implements \Magento\Framework\Event\ObserverInterface

    public function execute(\Magento\Framework\Event\Observer $observer)

    $item = $observer->getEvent()->getItem();
    $quote = $item->getQuote();  
        $myprice = 100;

  • after add this event it will provide me error "We can't add this item to your shopping cart right now." Jun 24, 2019 at 9:41
  • You did the wrong.I guess that you want to set a custom price for quote item ?
    – Amit Bera
    Jun 24, 2019 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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