0

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();
    }
  • may using observer cart item has been added again at cart – Amit Bera Oct 18 '16 at 12:03
2

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();
}
  • it's my pleasure :) – Nikunj Vadariya Oct 19 '16 at 6:35
  • it redirect me on cart page instead of sucess page. – denish vachhani Oct 19 '16 at 11:38
2

i have used Mage::getSingleton('checkout/cart')->truncate()->save(); which solve my issue.

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;
        }
        Mage::getSingleton('checkout/cart')->truncate()->save();
        $session->clear();
        $this->loadLayout();
        $this->_initLayoutMessages('checkout/session');
        Mage::dispatchEvent('checkout_onepage_controller_success_action', array(
            'order_ids' => array(
                $lastOrderId
            )
        ));
        $this->renderLayout();
    }

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.