I am creating a new cart addAction() in magento's checkout/controllers/cartController.php. My need is, Whenever a product is added to cart, all existing products in cart should be cleared except currently added one. That is,
If Nokia 3220 is added to an empty cart, It should be placed as an item.
And Later if Nokia N72 is added, Nokia 3220(ie the previous item) should be cleared from cart and Nokia N72 should be placed and so on.
I override the CartController.php and added the code to begining of addAction() in CartController.php,
$checkout_my_cart = Mage::getSingleton('checkout/cart'); $current_items = $checkout_my_cart->getItems(); foreach ($current_items as $item) { $itemId = $item->getItemId(); $checkout_my_cart->removeItem($itemId)->save(); }
But It clears the entire cart when I add a new item to replace existing one! I think It should not do it since I added the code in the begining of Addaction(). I tried by defining the above code as a function and calling it with addAction(). But story seems to be the same.
Any help will be appreciated.
Please Help.