Have you ever encountered the – ‘No such entity with orderId =‘ error during checkout in Magento 2? Here is the complete solution to find the reasons behind the error.
The error is usually displayed while loading a non-existing object in Magento 2 during the checkout process. Such an error should be solved on top-most priority as it prevents the customers to place orders on your Magento 2 store, and can affect conversions, sales, and overall customer experience.
The ‘No such entity with orderid =’ error generally occurs when you have third-party extensions installed on your store. In case you have installed plenty of Magento 2 extensions on your store, it can be highly time-consuming and tedious to find the root cause of such an error.
In such a scenario, performing a debug backtrace can help you to find the source of the issue. Here, in this blog post, I have provided a complete method to debug this issue that will help you find the causative source behind the ‘No such entity with orderid =’ error.
How to Debug ‘No such entity with orderId =’ Error in Magento 2?
To find the source of the ‘No such entity with orderId =’ issue in Magento 2, open the NoSuchEntityException.php file at vendor/magento/framework/Exception/ and replace the __construct function with the following code:
public function __construct(Phrase $phrase = null, \Exception $cause = null, $code = 0) { $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/aaa.log'); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info("============================="); $logger->info("__construct"); $logger->info(print_r($phrase,true)); $logger->info(print_r($cause,true)); $logger->info(print_r($code,true)); foreach (debug_backtrace() as $_stack) { $logger->info(print_r($_stack["file"],true));
Save the file and refresh the page. This will backtrace and generate aaa.log file at /var/log/ directory that will help you find the source of the ‘No such entity with OrderId’ issue. Once, you have backtraced the issue through the log, revert the changes in NoSuchEntityException.php file and save it.
That’s it! I hope this will help you to identify the source behind the issue to fix it.
In case you still have any doubts or queries regarding the issue, feel free to comment them down. I would be happy to help!
Also, share this amazing Magento 2 solution with your Magento friends via social media because ‘Sharing is Caring’.
Thanks for reading!