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

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

Found something useful, please give "Kudos" or "Accept as Solution" for Token of Appreciation.
Free Magento Extensions : https://magecomp.com/free-magento-extensions.html