0

I am facing this weird issue on the checkout page. We are using 3rd party payment module, which redirects customer to the payment page after placing order in Magento. In the controller, it tries to get the orderId from checkoutSession. Sometimes the ID is available in session and sometime it is missing in session.

Sometime it returns this value from checkoutSession:

{"quote_id_1":"114","last_added_product_id":"3345","cart_was_updated":false}

and sometimes it return below value from checkoutSession:

{"quote_id_1":"115","last_added_product_id":"4046","cart_was_updated":false,"last_quote_id":"115","last_success_quote_id":"115","last_order_id":"99","last_real_order_id":"000000099","last_order_status":"pending"}

I am not sure what is the issue. Please let me know, if anyone know about this issue.

FYI, we are using Magento 2.4.2 CE, saving session in DB and frontend in Redis.

1 Answer 1

0

Try this. In your payment module's return controller, instantiate these two classes in the constructor:

\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool

and in the function where you are retrieving the lastRealOrderId, before the function call, use them to clear/flush the 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(); }

It would seem this happens when you have full page cache on. Not sure it will work for you but it's worth a shot. So far it's worked for me. I've yet to still do more testing though.

Courtesy of this article: https://www.tigren.com/blog/magento-2-error-getlastrealorderid-doesnt-work/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.