2

I want to set a message when a disabled product is removed from the cart. Does anyone have any idea about it?

1 Answer 1

1

Need to create events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="controller_action_predispatch_checkout_cart_index">
        <observer name="vendor_module_quote_before" instance="Vendor\Module\Observer\BeforeQuote" />
    </event>
</config>

Also create Observer

<?php

namespace Vendor\Module\Observer;

class BeforeQuote implements \Magento\Framework\Event\ObserverInterface
{
    protected $_checkoutSession;
    public function __construct
    (
        \Magento\Checkout\Model\Session $checkoutSession
    }

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $quote = $this->_checkoutSession->getQuote();
        $notAdded = [];
        $deleted = [];
        foreach ($quote->getItemsCollection() as $item) {
            //your code
        }
    }
}

Using this code you get disabled items only one time.

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.