cancel
Showing results for 
Search instead for 
Did you mean: 

Cart items deletion while adding product to cart using observer

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.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now