magento shopping cart does not get clear

2019-08-06 08:26发布

问题:

I am developing an application in magento. I have 3 step checkout using onepage checkout. 1.Billing information 2. payment Info 3. Order review. Shipping information is merged with billing information. When I place an order shopping cart does not get clear. How to clear shopping cart after placing order successfully. but when I put this piece of code.

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

}

shopping cart gets clear but user automatically gets redirected from order summary to cart page.

I need to empty cart in savePaymentAction() in OnpageController.php Can anyone please guide me. how to fix this?

回答1:

Below are two solutions:

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

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



回答2:

Clear shopping cart

foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){

    Mage::getSingleton('checkout/cart')->removeItem( $item->getId() )->save();
}

//Redirect back to order view page
$this->_redirect('*/sales_order/view', array('order_id' => $order->getId()));

//Redirect back to cart page or wherever you wish
$this->_redirect('checkout/cart');

If you also want to Clear entire session

Mage::getSingleton(‘checkout/session’)->clear();


回答3:

Use any of the below-mentioned codes in ovserver after place order event.

1. <?php Mage::getSingleton('checkout/cart')->truncate(); ?>    
2. <?php Mage::getSingleton('checkout/session')->clear(); ?>
3. <?php $quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->delete(); ?>


标签: php magento