Magento 1.9.3 Cart Not Empty After Order Placement – Troubleshooting

cartmagento-1.9mini-cartshopping-cartupgrade

i have faced an issue. i have placed order but cart not empty after order success.

i have used $session->clear(); but no luck. anyone have idea to solve this. my successAction code is bellow.

public function successAction()
    {
        $notallowed = $this->getRequest()->getParam('na', false);
        if ($notallowed) {
            $this->_redirect('checkout/onepage');
            return;
        }
        $session = $this->getOnestepcheckout()->getCheckout();
        if (!$session->getLastSuccessQuoteId()) {
            $this->_redirect('checkout/cart');
            return;
        }
        $lastQuoteId           = $session->getLastQuoteId();
        $lastOrderId           = $session->getLastOrderId();
        $lastRecurringProfiles = $session->getLastRecurringProfileIds();
        if (!$lastQuoteId || (!$lastOrderId && empty($lastRecurringProfiles))) {
            $this->_redirect('checkout/cart');
            return;
        }
        $session->clear();
        $this->loadLayout();
        $this->_initLayoutMessages('checkout/session');
        Mage::dispatchEvent('checkout_onepage_controller_success_action', array(
            'order_ids' => array(
                $lastOrderId
            )
        ));
        $this->renderLayout();
    }

Best Answer

Please try to blow edited code and let me know it work or not.

public function successAction()
{
    $notallowed = $this->getRequest()->getParam('na', false);
    if ($notallowed) {
        $this->_redirect('checkout/onepage');
        return;
    }
    $session = $this->getOnestepcheckout()->getCheckout();
    if (!$session->getLastSuccessQuoteId()) {
        $this->_redirect('checkout/cart');
        return;
    }
    $lastQuoteId           = $session->getLastQuoteId();
    $lastOrderId           = $session->getLastOrderId();
    $lastRecurringProfiles = $session->getLastRecurringProfileIds();
    if (!$lastQuoteId || (!$lastOrderId && empty($lastRecurringProfiles))) {
        $this->_redirect('checkout/cart');
        return;
    }        

    // Add below code and check // 
    Mage::getSingleton('checkout/session')->clear();
    foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){

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

    $this->loadLayout();
    $this->_initLayoutMessages('checkout/session');
    Mage::dispatchEvent('checkout_onepage_controller_success_action', array(
        'order_ids' => array(
            $lastOrderId
        )
    ));
    $this->renderLayout();
}
Related Topic