cancel
Showing results for 
Search instead for 
Did you mean: 

Cart items deletion while adding product to cart using observer

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Cart items deletion while adding product to cart using observer

I want to delete items from cart while adding new products. I am observing : checkout_cart_add_product_complete event for this. My code is following:

 

 <checkout_cart_add_product_complete>
                <observers>
                    <secodaryproduct>
                        <type>singleton</type>
                        <class>secodaryproduct/observer</class>
                        <method>checkoutCartAddProductAddComplete</method>
                    </secodaryproduct>
                </observers
</checkout_cart_add_product_complete>

 

And for deleting products:

 

$cartHelper = Mage::helper('checkout/cart');
$cartHelper->getCart()->removeItem($product['item_id'])->save();

When i call this code without observer then this works fine and delete required items. But if i use this using observer then items not deleting from cart. I have also put the output in log file and item ids are printing correctly but my items are not deleting from cart. Please help.

1 REPLY 1

Re: Cart items deletion while adding product to cart using observer

@m__s

 

To remove the item before you add new a new item in cart, you have to use this event:

checkout_cart_update_items_before

Was my answer helpful? You can accept it as a solution.
200+ Premium Magento 2 Extensions Need help? Hire Magento Developer