When using the documented method for loading an Order Item:

  $order_item = \Drupal\commerce_order\Entity\OrderItem::load($order_item_id);

The Order Item loaded is a cached instance for anonymous users.

Steps to reproduce:

  1. Anonymous user adds an item to their cart
  2. Cart is deleted on backend by admin
  3. Order Item is loaded using above snippet as the anonymous user
  4. Order Item still exists, even though it was deleted

Is this a bug?

If not, is there a way to load the order item directly (uncached)?

Comments

quantumized created an issue. See original summary.

bojanz’s picture

There is no such caching on the Entity API level.
Your page might be cached a level above. You'll have to investigate.

3CWebDev’s picture

You were correct. The form where the logic resided was caching the entity.

Setting:

   $form['#cache'] = ['max-age' => 0];

Resolved my issue.

Thank you.

3CWebDev’s picture

Status: Active » Closed (works as designed)