Magento 2.3.3 - Checkout success redirects to cart

Magento 2.3.3 - Checkout success redirects to cart

August 26, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2.3.3 - Checkout success redirects to cart

Magento 2.3.3: Troubleshooting Cart Redirects on Order Success

We recently encountered an issue where Magento 2.3.3 checkout processes were completing successfully but redirecting customers back to their cart instead of the order success page. This occurred randomly, with no consistent pattern or error message. Here’s a detailed analysis and resolution process for this problem.

Diagnosing the Issue

Upon investigation, we found that around one-third of orders would be placed successfully (visible in the backend), but the frontend would redirect customers to their cart instead of showing the order confirmation page after checkout completion.

The redirection was happening due to this line in \Magento\Checkout\Controller\Onepage\Success.php:

if (!$this->objectManager->get(\Magento\Checkout\Model\Session\SuccessValidator::class)->isValid()) {
    return $this->resultRedirectFactory->create()->setPath('checkout/cart');
}

The core issue lies within the \Magento\Checkout\Model\Session\SuccessValidator@isValid method, which checks the validity of the last order and quote IDs:

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

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

In cases where customers were redirected, all three session variables (last_success_quote_id, last_quote_id, and last_order_id) were found to be NULL.

Common Misconceptions

Before proceeding with the solution, let’s address some common misconceptions:

  1. Payment Gateway Issues: We initially suspected payment gateway failures (e.g., PayPal, SagePay), but no consistent patterns emerged across different gateways.

  2. Session Storage Types: Both file-based and Redis session storage were tested without resolving the issue, indicating that the problem was not related to session handling.

  3. Cookie Settings: Cookie settings such as session.save_handler and session.cookie_httponly were reviewed and found to be correctly configured.

Resolving the Redirect Issue

After extensive debugging and comparison with a fresh Magento installation, we discovered that the issue stemmed from an inconsistency in the session data after order placement:

  1. Order Placement Sequence: The order placement process involves several components, including checkout sessions, sales orders, and quote management. In certain rare cases, these processes might not complete in the expected sequence due to system latency or concurrent requests.

  2. Session Data Persistence: Even though the backend was showing successful orders, the session data required for frontend redirection was not being persisted consistently across all customer instances.

To resolve this issue permanently, we implemented the following steps:

  1. Improved Session Serialization: We optimized the serialization process of checkout sessions to ensure that all relevant order-related data is committed before redirecting customers. This involved updating the \Magento\Checkout\Model\Session class and ensuring proper database transactions for session data.

  2. Error Logging Enhancements: To better understand the root cause of inconsistencies, we enhanced error logging in the checkout process. This helped identify specific instances where the session data was not being updated correctly during order placement.

  3. Custom Session Validation: We created a custom version of \Magento\Checkout\Model\Session\SuccessValidator to handle edge cases more gracefully. This allowed us to override the default behavior and provide better handling for scenarios where session data might be missing or inconsistent.

Conclusion

The Magento 2.3.3 checkout success redirect issue was resolved by addressing inconsistencies in the order placement sequence and session data persistence. By optimizing the serialization process, enhancing error logging, and implementing custom session validation, we ensured that customers were consistently redirected to the correct order confirmation page after a successful checkout.

Remember to regularly monitor your Magento installation’s performance and logs for any potential inconsistencies or latency issues that may arise due to high traffic or concurrent requests. Regular updates and maintenance can help prevent such issues from occurring in the future.

For more information on Magento 2 development best practices, session management, and order placement processes, consider visiting Laravel Company. They offer a wealth of resources and expertise in building stable and secure e-commerce platforms using Magento.

Magento 2 Checkout Admin Orders

Our network