scenario- when the user doing his shopping he added some products to the basket, that are shown in the minicart by default. But when the click on mini cart (or) when the user refresh the page i need to remove of stock items from minicart and display error msg "xxx,yyy products are removed due to out of stock" inside minicart . is this possible? if it is can anyone pls explain indetail. thanks.

1 Answer 1


You can use the sales_quote_save_before event to remove the out of stocked item from the quote place your logic in commented section


<event name="sales_quote_save_before">
    <observer name="remove_out_of_stock_item" instance="Vendor\Module\Observer\Remove"/>


public function execute(Observer $observer)

        /** @var $quote \Magento\Quote\Model\Quote */
        $quote = $observer->getEvent()->getQuote();
        $result = $quote->getAllItems();
        foreach ($result as $item) {
          // get product from item and check stock status if out of stock then delete the item else proceed


    return $this;

  • thanku @Ghulam.M. When that event is triggered
    – Mani
    Commented Mar 14, 2022 at 10:02
  • and how can i add error message in the minicart
    – Mani
    Commented Mar 14, 2022 at 10:22

Your Answer

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

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