I deleted a store. The store has a shopping cart in progress, now when I click on a user or on the shopping cart tab of the admin menu, I get the following error :

The website encountered an unexpected error. Please try again later.

Message TypeError: Argument 2 passed to Drupal\commerce\Context::__construct() must implement interface Drupal\commerce_store\Entity\StoreInterface, null given, called in /home/www.domaine.com/public_html/web/modules/contrib/commerce/modules/order/src/OrderRefresh.php on line 137 in Drupal\commerce\Context->__construct()

CommentFileSizeAuthor
#10 OrderRefresh.php_.patch2.75 KBvindesh

Comments

zenimagine created an issue. See original summary.

bojanz’s picture

Category: Bug report » Support request
Priority: Critical » Normal
Status: Active » Fixed

Yes, if you delete data that is in use, you will break things.

There are several open issues about this in the issue queue. To be solved at a later date.

zenimagine’s picture

This problem blocks my entire site, do I have to restore it or is there a solution? Thank you

bojanz’s picture

Go to devel/php and delete the cart order using normal Entity API methods ($order = Order::load($your_id); $order->delete())

zenimagine’s picture

I do not master devel, can I delete the order directly in the database ?

bojanz’s picture

I would not recommend it.

zenimagine’s picture

In the database, I deleted the problematic order in the following table :

commerce_order

After I went on :

/admin/modules/uninstall

And I clicked on the following two links :

There is content for the entity type: Order item. Remove order items.
There is content for the entity type: Ordre. Remove commandes.

Now the site works and I do not see any error in the report.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

thirstysix’s picture

Hi,

I have an doubt. I got the same error when I am after deleting a store. I removed the order items. but, I can't able to remove the orders.
"There is content for the entity type: Order. Remove orders." How can I fix this issue?
I need to remove the existing orders

Thanks in Advance.

vindesh’s picture

StatusFileSize
new2.75 KB

I faced this error on Drupal 8.5.x with commerce order module and resolved this error.

sourabhbhalerao’s picture

Hi,
I am also getting same error on drupal 8.6 when i create two stores and then create two products and assign store to each product then I delete one store other than default store then it generate error but when i go to edit product page and save it again then it is working proper....another thing i have check with another process if we delete default store and leave second store as it is then it is not assign as default auto and add to cart is not properly working.

Thanks

mesh’s picture

Here's what worked for me.
0. Check there is at least one store created (If you have accidentally deleted an existing one)
1. Temporarily apply the patch
2. Go to Extend > Uninstall
3. Find 'Commerce Order' and click these two (Make sure the patch is applied, or it will throw up the same errors)
3a. 'Remove orders'
3b. 'Remove order items'
4. Revert the patch

It would be really helpful if people mentioned the status of this patch, if it will be included in future updates or not.

zenimagine’s picture

Issue summary: View changes
rituraj.gupta’s picture

Hi @mesh,

Nothing is working. I have applied patch but same error displaying.
The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\commerce_store\Entity\Store::getCustomer() in Drupal\commerce_order\OrderRefresh->refresh() (line 139 of modules\contrib\commerce\modules\order\src\OrderRefresh.php).

TheWinkingSkeever’s picture

Can confirm #7 worked for me when I deleted a store that still had somewhere some data in a users cart.

Delete the problem cart order from the database fixed my problem. I had an error when I tried to remove them from the uninstall/module list

FredJF’s picture

Clearing carts works for me:

DELETE FROM `commerce_order` WHERE `cart` = 1

Ezequiel Smith’s picture

I had the same problem after removing stores from my products, what I did to fix it was the following:

  1. Create a new store and see the store id in the database (in the commerce_estore table):
  2. SELECT * FROM commerce_store;

  3. Change the "store_id" field of all orders to the store id we have created (you should be careful if you already have orders with existing stores -> filter correctly with the where clause of the query):
  4. UPDATE commerce_order SET store_id=7 WHERE store_id NOT IN (8,9)
    (In the example i was deleted stores with id 1 to 6, and i have already orders with stores 7,8,9)

  5. In theory, the add to cart button and similar functions affected should be working ...

This is not "the solution", but it could help ... I'm quite paranoid about running DELETE queries (in ignorance) in the database hehe