Magento2: Multisite / No such entity with cartId = XX

Created on 7 Sep 2016  路  30Comments  路  Source: magento/magento2

  1. Magento 2.1.1, Composer-based
  2. HAProxy, Varnish 4, Nginx, PHP-FPM 7.0.10-1, MariaDB

    Steps to reproduce

  3. Setup another website, store & store view

  4. Copy some products over to the new website (for testing)
  5. Create a new order from Sales -> Orders in magento backend while using the new websites store view
  6. Submit the order

    Expected result

  7. Order creation

    Actual result

  8. Return with exception _No such entity with cartId = XX_

What I tested so far:

  1. Same customer, default Website -> works
  2. Same customer, default Website, custom store view -> works
  3. Quotes are getting generated in DB
  4. Setup a 3rd ws, store, store view -> same result, doesn't work
  5. Cleaned all quotes in the DB
  6. Logged in customers can't place orders in any store frontend
  7. Guest orders do work...

Regards
Jan

Cannot Reproduce Format is not valid needs update bug report

Most helpful comment

I have the same issue on version 2.1.3 (multiwebsite)
For example, I need to retrieve a quote after the order is placed from the admin panel

  1. I catch the checkout_submit_all_after event in my custom observer to retrieve the order which was placed from the admin panel and NOT from the default store.
  2. I get the quote_id from the order object and try to retrieve the quote using the \Magento\Quote\Model\QuoteRepository::get() method.
  3. Meanwhile, this method executes the \Magento\Quote\Model\QuoteRepository::loadQuote() method which sets the current store ID before the quote execution.
  4. The problem is that the current store has always the default store ID in the admin panel (on the fronted everything is OK).
  5. As result I catch the No such entity with cartId = ... exception, because Magento tries to retrieve quote with this ID from the default store, which does not exist.

As a workaround, I always have to set the current store using StoreManager before quote execution in the admin scope, but I think this is not acceptable.

@magento-team, please fix this issue asap. Thanks.

All 30 comments

From firebug:

{"message":"An error occurred on the server. Please try to place the order again.","trace":"#0 \/var \/www\/html\/vendor\/magento\/framework\/Interception\/Interceptor.php(146): Magento\\Checkout\\Model \\PaymentInformationManagement->savePaymentInformationAndPlaceOrder(8, Object(Magento\\Quote\\Model\ \Quote\\Payment\\Interceptor), Object(Magento\\Quote\\Model\\Quote\\Address))\n#1 \/var\/www\/html\/var \/generation\/Magento\/Checkout\/Model\/PaymentInformationManagement\/Interceptor.php(26): Magento\\Checkout \\Model\\PaymentInformationManagement\\Interceptor->___callPlugins('savePaymentInfo...', Array, Array )\n#2 [internal function]: Magento\\Checkout\\Model\\PaymentInformationManagement\\Interceptor->savePaymentInformationAndPlaceOrder (8, Object(Magento\\Quote\\Model\\Quote\\Payment\\Interceptor), Object(Magento\\Quote\\Model\\Quote\ \Address))\n#3 \/var\/www\/html\/vendor\/magento\/module-webapi\/Controller\/Rest.php(307): call_user_func_array (Array, Array)\n#4 \/var\/www\/html\/vendor\/magento\/module-webapi\/Controller\/Rest.php(216): Magento \\Webapi\\Controller\\Rest->processApiRequest()\n#5 \/var\/www\/html\/var\/generation\/Magento\/Webapi \/Controller\/Rest\/Interceptor.php(37): Magento\\Webapi\\Controller\\Rest->dispatch(Object(Magento\ \Framework\\App\\Request\\Http))\n#6 \/var\/www\/html\/vendor\/magento\/framework\/App\/Http.php(135 ): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\ \Http))\n#7 \/var\/www\/html\/vendor\/magento\/framework\/App\/Bootstrap.php(258): Magento\\Framework \\App\\Http->launch()\n#8 \/var\/www\/html\/pub\/index.php(51): Magento\\Framework\\App\\Bootstrap->run (Object(Magento\\Framework\\App\\Http))\n#9 {main}"}

Same thing here, many stores. Default store orders from admin are OK, cannot create orders from other stores, I get a No such entity with cartId = XX error.

@Ubeo - did you try creating frontend orders? In one of our clients shop they seems to be blocked...

@gewaechshaus yes, it works on frontend.

Got the same issue with a multistore setup. Can only create backend orders for the default store. Choosing an other store results in this error message.

@PascalBrouwers - what's going on in your frontend? Our clients guest frontend orders are partially blocked 2, so be aware...

Frontend is ok. But we like to be able to make a backend order as well ;)

Any updates about it ?

I have the same issue on version 2.1.3 (multiwebsite)
For example, I need to retrieve a quote after the order is placed from the admin panel

  1. I catch the checkout_submit_all_after event in my custom observer to retrieve the order which was placed from the admin panel and NOT from the default store.
  2. I get the quote_id from the order object and try to retrieve the quote using the \Magento\Quote\Model\QuoteRepository::get() method.
  3. Meanwhile, this method executes the \Magento\Quote\Model\QuoteRepository::loadQuote() method which sets the current store ID before the quote execution.
  4. The problem is that the current store has always the default store ID in the admin panel (on the fronted everything is OK).
  5. As result I catch the No such entity with cartId = ... exception, because Magento tries to retrieve quote with this ID from the default store, which does not exist.

As a workaround, I always have to set the current store using StoreManager before quote execution in the admin scope, but I think this is not acceptable.

@magento-team, please fix this issue asap. Thanks.

Experiencing the same issue on CE 2.1.3.

Same here...

Same here. having issue in CE 2.1.2

I'm having this issue on and off for the last couple of days.

After downloading an updated database from our staging server, when I try to checkout I was getting error message "No such entity with cartId = 0".

However, if I switch to a new incognito browser I was able to checkout, while still getting the error in my regular browser.

The issue seems to have something to do with the wrong ID getting posting to estimate-shipping-methods rest api.

Error in regular browser posting
/rest/default/V1/guest-carts/582/estimate-shipping-methods

Incognito browser posting
rest/default/V1/guest-carts/8c5a23bf5bfb3040cce9c340af04b973/estimate-shipping-methods

Which causes the function below to return zero because 582 is not a valid mask_id.

Magento version 2.1.3

vendor/magento/module-quote/Model/GuestCart/GuestShippingMethodManagement.php

    public function estimateByExtendedAddress($cartId, AddressInterface $address)
    {
        /** @var $quoteIdMask QuoteIdMask */
        $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');

        return $this->getShipmentEstimationManagement()
            ->estimateByExtendedAddress((int) $quoteIdMask->getQuoteId(), $address);
    }

I'm getting this same issue on 2.1.4

I'm also having the problem in 2.1.5 and it's causing lots of problems. Please fix asap.

Hi, @gewaechshaus. We need more information about your configuration to reproduce this issue. Please, specify payment and shipping methods you use and your second website's settings.

Hi, @asrar7787. Tried to reproduce it as you told but still can't get this error message.
Can you provide the detailed steps we must follow to reproduce this issue?
Here is my steps:

  1. Create several websites/stores/store views
  2. Set up multidomains fr some of them
  3. Create simple product and Save it
  4. Assign it for other websites
  5. Create Order from backend as a Guest Customer
  6. Choose one of the available store views
  7. Fill all required fields
  8. Submit order

What i missed? What i must to do to reproduce it?

Hi @IlnitskiyArtem, have you tried following the steps given by @alexpoletaev ?
https://github.com/magento/magento2/issues/6522#issuecomment-276027109
Those seem to be detailed enough.

@korostii

The issue still persists in EE 2.1.6.

I will not be verbose again as other members already did earlier, it's a waste of time, if you do not really appreciate others time!

Anyway, debug this class in multi-store installation for admin orders
vendor/magento/module-quote/Model/QuoteRepository.php on line 192 and you will see that $shardeStoreIds at one point will be having no array element, means default store view. This in turn causes the error.

Why core team not taking it seriously given that merchants spend money for Enterprise edition?!

I would suggest a member of advisory board team should take a look into it.

And do not just tag can not reproduce please.

This is misleading, an Enterprise Level misleading, as I spent few hours considering the issue does not exist. So I had to debug all other modules and stuff. But eventually, it's the core code!

I would not mind screen cast with you tbh!

M2 guys, please acknowledge this issue and fix that asap.

I think I am receiving this error.
I get this error whenever I try to edit an order in the backend that is not part of the default shop. (by edit I mean the cancel/reorder edit where you add extra products change shipping methods etc.)

As a further test I added code to the root index.php to change website run code param to my second store effectively making that my default store. When I did this I could edit orders for my second store without errors but I would get errors whenever I tried to edit an order from the default store.

@alexpoletaev

Hi mate, would you mind sharing/explaining your code where and how you were able to implement your workaround please?

Thanks

Asrar

Hi @asrar7787, we had this issue with the 3rd party module, but the problem is that magento always retrieves a quote (if the QuoteRepository was used) from the admin area for the default store, so you need to find the place where you catch this exception and provide a store id like this:

$quote = $this->quoteRepository->get($quoteId, [$order->getStoreId()]);

or, at least, like this:

$this->storeManager->setCurrentStore($order->getStoreId());
$quote = $this->quoteRepository->get($quoteId);

it's better to use the first example. So using this way you telling Magento for which store you want to retrieve the quote.

I was having trouble finding the correct place to place the code mentioned above. I was eventually able to work out a slightly hacky way of doing this (do it at the start of all order saves in admin). I'm still testing this for any possible issues it might cause so use at your own risk

/vendor/magento/module-sales/Controller/Adminhtml/Order/Create/Save.php
try {
// hack to let it save in multistores
$om = \Magento\Framework\App\ObjectManager::getInstance();
$manager = $om->get('Magento\Store\ModelStoreManagerInterface');
$manager->setCurrentStore($this->_getSession()->getQuote()->getStoreId());
// end hack

I had to create a 'before' plugin for order Magento\Sales\Controller\Adminhtml\Order\Create\Save
so no core hack necessary, a Magento 2 way fix ;-), cheers @nick-iFactory

see below:

the etc/adminhtml/di.xml for declaring the plugin:

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Controller\Adminhtml\Order\Create\Save">
        <plugin name="namespace_modulename_adminhtml_order_create_save_before_execute"
                type="Namespace\Modulename\Plugin\Sales\Controller\Adminhtml\Order\Create\Save"
                sortOrder="1"
                disabled="false"
        />
    </type>
</config>

and the plugin for controller

<?php

namespace Namespace\Modulename\Plugin\Sales\Controller\Adminhtml\Order\Create;

use Magento\Backend\Model\Session\Quote as BackendSessionQuote;
use Magento\Store\Model\StoreManagerInterface;

class Save
{
    protected $backendSessionQuote;

    protected $storeManagerInterface;

    public function __construct(
        BackendSessionQuote $backendSessionQuote,
        StoreManagerInterface $storeManagerInterface
    ) {
        $this->backendSessionQuote = $backendSessionQuote;
        $this->storeManagerInterface = $storeManagerInterface;
    }

    public function beforeExecute(
        \Magento\Sales\Controller\Adminhtml\Order\Create\Save $subject
    ) {
        $this->storeManagerInterface->setCurrentStore($this->backendSessionQuote->getQuote()->getStoreId());
        return;
    }
}

That should work.

@orlangur Thanks for the update, I will give that a go.

Seeing this issue on 2.1.9, except I'm not running multistore, we only have one storefront. Also I'm not seeing it on the back end, we are getting this problem during regular checkout.

@asrar7787 - I was going to try your solution, but then I realized that this is a fix for the admin, so not applicable to people buying via the regular cart.

Would setting the site to single store mode (assuming there is no need for multistore) resolve this issue?

@aeu please keep in mind that single-store mode has its own issues, most notably #7392

We are experiencing this issue quite a lot as well on Magento 2.1.6.

Here are my thoughts:

What I found is that every time the order is created it throws that "No such entity" exception. When the quote is converted to order, it sets is_active to 0. Later on, on success page, it tries to get the quote and because it has is_active as 0, it throws that exception.
But, in the code it doesn't render that error, it just sets quote id to 0 if that error is caught. Most likely it is done to remove that quote from the customer's session after placing order successfully.
So, taken above into account, it seems that most likely the bug is not in the error itself, but in the rendering - this error simply shouldn't be seen, but somehow it gets visible for the customer in some rear cases. Probably because of some ajax requests triggered too fast / too slow, but not sure exactly, these are just guesses.

Any comments from the devs about this? Are my observations correct?

Thanks.

Was this page helpful?
0 / 5 - 0 ratings