I have added a custom product attribute with yes/no options. I need to delete products if 'no' attribute option is selected. I have successfully removed cart item using "controller_action_predispatch_checkout_cart_index" event. but i face issue in the following scenerio:

First i set product attribute to yes . This will allow customers to add the product in cart. now go to frontend add product to cart, now go back to admin and set the product attribute option as no. so this will not allow product to cart. but i face trouble for already added product. so i created observer to automatically remove on cart predispatch. but what if customer go directly to checkout page .

any ideas what event i must call . so that it will remove all the products already added to cart ?


Thank you for your response..

I think Magento\Checkout\Model\Cart 's addProduct() is called only when product is added to cart.. how about already added to cart..

For example I add product in cart .. then admin set conditions and here let added product does not satisfy the conditions.. so this product does not get removed .. Magento\Checkout\Model\Cart 's addProduct() is triggered only while adding product to cart

1 Answer 1


Using controller_action_predispatch_checkout_cart_index is not the way to go as customer may not visit cart page, aslo if you want this for order place in admin, it won't work.

You should add a plugin on Magento\Checkout\Model\Cart 's addProduct() function as done in following post.

Magento2 - How to stop a product from getting added to cart programmatically?

You can get the products added in quote item, load them using product model and check you validation and throw the exception.

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.