2
$this->checkoutSession->getLastRealOrder()
$this->checkoutSession->getLastRealOrderId()

returning null after payment gateway redirect.

Strange thing is that it is working some time and after it stops working.

What is the issue and how to get paid order on success page ?

2
  • I have same issue in Magento 2.3.6-p1 Mar 2, 2021 at 20:40
  • I am facing the same issue on Magento 2.4.2, disabled cache, varnish etc, issue still persists don't know what is wrong !! Magento Sucks !!
    – Dhimant
    Jul 21, 2021 at 10:40

1 Answer 1

1

Have you tried clearing the cache?

If it doesn't work, try following these steps:

  1. Pass Magento\Framework\App\Cache\TypeListInterface and Magento\Framework\App\Cache\Frontend\Pool to your file’s constructor as the following:

    public function __construct(
        Context $context,
        \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
        \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
    ) {
        parent::__construct($context);
        $this->_cacheTypeList = $cacheTypeList;
        $this->_cacheFrontendPool = $cacheFrontendPool;
    }
    
  2. Add these lines to the method where you want clear/ flush cache:

    $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');
    foreach ($types as $type) {
        $this->_cacheTypeList->cleanType($type);
    }
    foreach ($this->_cacheFrontendPool as $cacheFrontend) {
        $cacheFrontend->getBackend()->clean();
    

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.