Change record status: 
Project: 
Introduced in branch: 
4.x
Introduced in version: 
Description: 

Commerce now uses separate entity access operations for what customers do with their orders. The update operation on orders and order items now covers only the merchant's edit, and is granted only by permissions.

  • update_cart (orders and order items): granted by commerce_cart to customers on their own draft carts and cart items. It is not granted while the order is locked, and not on locked order items.
  • checkout (orders): granted by commerce_checkout to customers on their own non-empty orders from a published store, if they have the access checkout permission. Canceled orders are always forbidden.

Previously, commerce_cart granted customers update on their carts and denied it on admin routes using the route.name cache context. That workaround has been removed.

API changes

  • \Drupal\commerce_checkout\Controller\CheckoutController::checkAccess() has been removed. The checkout form route and the payment return/cancel routes now use _entity_access: 'commerce_order.checkout'.
  • The CheckoutController constructor no longer takes the cart session ($cart_session) argument.

Behavior changes

  • Users with the administer commerce_order permission now pass checkout and update_cart on any order. Previously, only the order's customer could access its checkout.
  • Customers can no longer change their carts through core JSON:API or REST, since they no longer have update access.

What to change

Routes that used the removed access callback:

Before:

requirements:
  _custom_access: '\Drupal\commerce_checkout\Controller\CheckoutController::checkAccess'

After:

requirements:
  _entity_access: 'commerce_order.checkout'

Code that checks customer access to a cart, such as payment gateway routes used during checkout (approve, return, notify), must check checkout (or update_cart for changing the cart's contents) instead of update:

Before:

requirements:
  _entity_access: 'commerce_order.update'

After:

requirements:
  _entity_access: 'commerce_order.checkout'

In PHP:

// Before.
$order->access('update', $account);
// After.
$order->access('checkout', $account);
// or, to change the cart's items:
$order_item->access('update_cart', $account);

Subclasses of CheckoutController must drop the $cart_session argument from their constructor and create() calls.

Impacts: 
Site builders, administrators, editors
Module developers