no such entity with customerid magento 2 error

No such entity with customerid Magento 2

Rate this article

Share this article

If you receive the error message “No such entity.”, “No such entity with” or “No such entity with customerId” in Magento 2, the issue usually occurred when you try to load not existing object via Magento 2 Repository Class.

magento 2 no such entity with customerid

Add a search bar to Magento

No such entity with customerid Magento 2- How to fix

Sorry to say this, but as usual, after upgrading Magento versions something is wrong at the end. I did have no exceptions and no errors before. Now upgrading to 2.3.2 I get exceptions like: [2019-06-25 21:46:34] main.CRITICAL: Keine Eintrag mit customerId = 1 {“exception”:”[object] (Magento\Framework\Exception\NoSuchEntityException(code: 0): Keine Eintrag mit customerId = 1 at /var/www/vhosts/hopfenmuseum-tettnang.de/magento.hopfenexpress.de/vendor/magento/framework/Exception/NoSuchEntityException.php:50)”} []

To debug this issue, please open the file

vendor/magento/framework/Exception/NoSuchEntityException.php

and at the beginning of the __construct method temporary add debug backtrace code:

foreach (debug_backtrace() as $_stack) {
    echo ($_stack["file"] ? $_stack["file"] : '') . ':' .
        ($_stack["line"] ? $_stack["line"] : '') . ' - ' .
        ($_stack["function"] ? $_stack["function"] : '');
}
exit();

example:

public function __construct(Phrase $phrase = null, Exception $cause = null, $code = 0)
 {
    foreach (debug_backtrace() as $_stack) {
        echo ($_stack["file"] ? $_stack["file"] : '') . ':' .
            ($_stack["line"] ? $_stack["line"] : '') . ' - ' .
            ($_stack["function"] ? $_stack["function"] : '');
     }
    exit();
    if ($phrase === null) {
        $phrase = new Phrase('No such entity.');
    }
    parent::__construct($phrase, $cause, $code);
 }

save the file and refresh the page.

Conclusion:

You will see the debug backtrace that will allow you to define the issue source and you will get an idea of how to fix it.

Usually, third-party Magento 2 extensions lead up to this problem, so you can override their code and add a “try-catch” exception.

Don’t forget to revert changes in NoSuchEntityException.php file after you’re finished.

Just like in Magento the custom search in drupal is pretty tricky to set up and can cause a lot of issues. However, there are good drupal custom search solutions that can be used to set up drupal search easily and fast with even sophisticated features like drupal faceted search.

Are you showing the right products, to the right shoppers, at the right time? Contact us to know more.
You may also like