Magento 2 – Checkout/Onepage/Success Redirects to Cart

checkoutmagento2order-confirmationpaypal

When I use PayPal Plus(PayPal, credit cards) ,the checkout success page is not shown. Instead is redirected to checkout/cart/. enter image description here

The redirection happens in this file:

Magento\Checkout\Controller\Onepage\Success

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Checkout\Model\Session;

/**
 * Test if checkout session valid for success action
 *
 * @api
 */
class SuccessValidator
{
    /**
     * @var \Magento\Checkout\Model\Session
     */
    protected $checkoutSession;

    /**
     * @param \Magento\Checkout\Model\Session $checkoutSession
     * @codeCoverageIgnore
     */
    public function __construct(
        \Magento\Checkout\Model\Session $checkoutSession
    ) {
        $this->checkoutSession = $checkoutSession;
    }

    /**
     * @return bool
     */
    public function isValid()
    {

        if (!$this->checkoutSession->getLastSuccessQuoteId()) {
            return false;
        }

        if (!$this->checkoutSession->getLastQuoteId() || !$this->checkoutSession->getLastOrderId()) {
            return false;
        }
        return true;
    }
}

I found out that all three :

$this->checkoutSession->getLastSuccessQuoteId()
$this->checkoutSession->getLastQuoteId()
this->checkoutSession->getLastOrderId()

return null.
Obviously there is something to do with the session but this is the furthest I could go.
The orders are completed and successful.Its just the order confirmation page that is not shown.

Best Answer

Look very carefully to your var/log/system.log.

In my case, I was missing some important information there and the problem was Redis. The session was being locked by some other process and didn't allow Magento to update the cart/quote session there.

I just noticed that when added a breakpoint to \Magento\Checkout\Controller\Onepage\Success::execute and looking at my tail -f var/log/* terminal tab.

Update: I faced the problem again and Redis config was the problem. I just changed the break_after_frontend from 5 to 15 in app/etc/env.php as I described here. It worked for me.

Related Topic