4

I want to programm Magento in such a way that the quantity of cart displays zero even if the product is Added into the cart. Initially there will be one product into cart but it hasn't to be displayed on the top menu cart link

I have used following code but I don't get enough response.

Mage::getModel('checkout/cart')->getQuote()->setItemsQty(0);
1

Clear shopping cart

foreach (Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ) {
    Mage::getSingleton('checkout/cart')->removeItem($item->getId())->save();
}

If you want to Clear entire session

Mage::getSingleton('checkout/session')->clear();
| improve this answer | |
0

If you have a large number of customers quotes then deleting them by using loop might be time and resource consuming. You can clear/delete all customers cart items (all active sales quotes) by using the following SQL query:

DELETE FROM sales_flat_quote WHERE is_active = 1;

is_active = 0 means those quotes have been converted into orders, i.e. customer has placed order for those quotes.

is_active = 1 means quotes that have not been ordered, i.e. quotes present in the shopping cart of customers

Running this query will automatically delete related rows (quote items) from sales_flat_quote_item table through foreign key constraint.

| improve this answer | |
  • 2
    Please don't add 2 answers if they are not needed. You can always edit a previous answer and provide additional data. – Marius Dec 18 '14 at 7:55
  • Please don't ever do it this way. – chaoticgeek Dec 24 '14 at 13:59
-1

Below are the list of options and all options are working for my case.

1.Mage::getSingleton('checkout/session')->clear();

2.Mage::getSingleton('checkout/cart')->truncate();

3.$quote = Mage::getSingleton('checkout/session')->getQuote(); 
$quote->delete();

4.Mage::getSingleton('checkout/cart')->truncate()->save();

5.Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

6.foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){
    Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
}

7.$cartHelper = Mage::helper('checkout/cart');
    $items = $cartHelper->getCart()->getItems();       
    foreach ($items as $item)
    {
            $itemId = $item->getItemId();
            $cartHelper->getCart()->removeItem($itemId)->save();
    }

8.$quote = Mage::getSingleton('checkout/session')->getQuote();
$item = $quote->getItemByProduct($product);
$quote->removeItem($item->getId());

9.$quote->removeAllItems();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.