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

Order processors that modify an order item's unit price must now preserve the "overridden" flag of the unit price.

Background

OrderItemInterface::setUnitPrice() takes a second $override argument that defaults to FALSE. Processors modifying the unit price (e.g. display-inclusive tax and promotions) used to call it without that argument, which silently cleared the flag. On the next refresh, the order item was treated as having a regular price and its unit price was re-resolved, losing the overridden unit price.

In addition, the order refresh now resets the unit price of order items that are not re-resolved (overridden unit prices, and order items without a purchased entity) to its unprocessed value before invoking the order processors. Previously, the processors' modifications were compounded on every refresh.

What you need to do

If your order processor modifies the unit price, pass the current flag:

Before:

$order_item->setUnitPrice($new_unit_price);

After:

$order_item->setUnitPrice($new_unit_price, $order_item->isUnitPriceOverridden());

Processors should always compute the new unit price from the current unit price, the order refresh guarantees it is the unprocessed value. Processors that work around the compounding (e.g. by storing and restoring the original unit price themselves) can drop that logic.

If you override OrderRefresh::refresh() without calling the parent implementation, call resetUnitPrice() for each order item before invoking the processors, and recordProcessedUnitPrice() after.

Existing orders

Draft orders containing order items without a purchased entity, on stores using display-inclusive tax or promotions, may already have inflated unit prices from previous refreshes. These are not corrected automatically: re-set the unit price or recreate the order item.

Impacts: 
Module developers