1 Comment

Re-adding products to cart on payment failure requires refresh

Zend_Log_Formatter_Simple undefined Magento 1.7
Accessing Magento 2 content/functionality from third party CMS

I referred this url (Prevent Magento to empty cart after failed payments) and came up with the following code to add the products back again to the cart.

public function failureAction()
{ 
    $lastQuoteId = $this->getOnepage()->getCheckout()->getLastQuoteId();
    $lastOrderId = $this->getOnepage()->getCheckout()->getLastOrderId();        

    if ($lastQuoteId && $lastOrderId) {
        $orderModel = Mage::getModel('sales/order')->load($lastOrderId);
        $quote = Mage::getModel('sales/quote')->load($lastQuoteId);
        $quote->setIsActive(true)->save();
    }
    if (!$lastQuoteId || !$lastOrderId) {
        $this->_redirect('checkout/cart', array("_forced_secure" => true));
        return;
    }

    $this->loadLayout();
    $this->renderLayout();  
}

I’m displaying a page on the failureAction which the 3rd party payment gateway redirects. The problem is that when the payment gateway redirects and the page is shown for the first time, the cart is displayed as empty. When i refresh the page the products get added to the cart. How can i achieve this without refreshing the page?

Related Posts

  • Redirect user to order review step of checkout/onepage/ on payment failure Magento (0)
    For now my 3rd party payment gateway redirects me to the checkout/onepage/failure/ page which has a url to go back to the cart view. With the help of this http://ka.lpe.sh/2011/12/31/magento-getting-back-shopping-cart-items-after-order-fails/ I managed to add the products back to […]
  • Place order, validates correctly returns to empty shopping cart page (0)
    ive got a weird issue with Magento, we recently applied the SUPEE-7405 patch on 1.6.1 and after this, as soon as you make a payment via the onestepcheckout, it returns to the continue shopping page after the payment has been processed by the gateway provider. This might be quite […]
  • Magento Payment successful redirect issue (1)
    In my site I have issue in payment redirect URL. It works fine in Google Chrome but it redirects to empty cart page in Firefox. When I clicked on place order button, I redirect on Payment gateway page, after successful payment, the URL of site not going on Success page, it redirects […]
  • Magento Custom Payment method (2)
    I Created a Custom Payment Method Module and its work perfectly but in the redirect to success page i use this code below: Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure' => true, '_query'=> $parameters)); in this code i created an […]
  • Redirect to external url after order creation (0)
    I am making a payment gateway and I need to redirect from the invoice page to an external url. Basically when an order is created at Magento I create an order in a 3rd party app with curl, then I get unique ID from that order which is used to redirect to an external invoice page. […]
  • Magento 2.1: How to handle custom payment grand total mismatch upon return to the merchant ?site (0)
    The customer payment gateway I'm working on is based on the workflow of PayPal Express checkout. Upon the checkout, the user will be redirected to the payment site and then return back to the Magento store after the payment is completed. Here's the catch, PayPal Express keep the […]
  • Magento 2.1: How to handle custom payment grand total mismatch upon return to the merchant ?site (0)
    The customer payment gateway I'm working on is based on the workflow of PayPal Express checkout. Upon the checkout, the user will be redirected to the payment site and then return back to the Magento store after the payment is completed. Here's the catch, PayPal Express keep the […]
  • Magento 2: Unable to Get Cart Information (1)
    In addition of Magento 2: How to show/hide payment method on basis of amount Below code i have namespace VendorModuleModel; class Express extends MagentoPaypalModelExpress { public function isAvailable(MagentoQuoteApiDataCartInterface $quote = null) { $_objectManager […]
  • Magento 2: Unable to Get Cart Information (1)
    In addition of Magento 2: How to show/hide payment method on basis of amount Below code i have namespace VendorModuleModel; class Express extends MagentoPaypalModelExpress { public function isAvailable(MagentoQuoteApiDataCartInterface $quote = null) { $_objectManager […]
  • Magento 2: Unable to Get Cart Information (1)
    In addition of Magento 2: How to show/hide payment method on basis of amount Below code i have namespace VendorModuleModel; class Express extends MagentoPaypalModelExpress { public function isAvailable(MagentoQuoteApiDataCartInterface $quote = null) { $_objectManager […]
Zend_Log_Formatter_Simple undefined Magento 1.7
Accessing Magento 2 content/functionality from third party CMS

1 Comment on this article

  • User November 12, 2016

    Quote Object $quote does not set active at current checkout session until page refresh.So face this issue.

    As per as,magento anysession variable does effect until one rendere.

    So ,i would suggesting you create another Action (example: testAction()) and

    after doing $quote->setIsActive(true)->save(); redirect to that testAction url by $this->_redirect('*/*/test'); and your testAction and create an view

    public function testAction()
        { 
            $this->loadLayout();
            $this->renderLayout();  
        }
    

    Reply

Add a comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax