Problem/Motivation

Whenever a shipment is added, edited, or removed the order is refreshed
https://git.drupalcode.org/project/commerce_shipping/-/blob/8.x-2.x/src/...

While this is fine for draft orders and carts it can lead to data loss when the order is refreshed for placed orders. Placed orders should not change unless expressly done by an administrator. The order refresh causes line item prices to be updated, promotions to be reevaluated, taxes recalculated.

When shipments are changed there are three things that do need to happen on placed orders:

  1. The shipping adjustment total on the order needs to be updated to reflect the total cost of the shipments
  2. The shipping promotions need to be recalculated. Other promotions need to remain untouched.
  3. The tax for shipping, if applicable, needs to be recalculated and an event fired for any tax integrations to subscribe to

Steps to reproduce

Add, edit, or delete a shipment using the Shipments tab UI in the order administration area after an order has already been placed.

Proposed resolution

Trigger a shipping specific order refresh on non draft orders.

Possible ways of doing this:
Call the provided functions that commerce_shipping defines for the order refresh to only refresh shipping specific parts of the order. Probably the wrong way.

Provide a shipment refresh service that handles the refresh similar to the core one but skips anything that is not related to shipping.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rhovland created an issue. See original summary.

rhovland’s picture

rhovland’s picture

Here's a patch that disables refresh unless it's a draft order and does the bare minimum: updates the shipping adjustments after shipment save.
As I argued in the related issue, non draft order edits should be in control of the administrative user and doing things that change the order in meaningful ways (taxes, promotions, etc) should be controlled by the admin user not an automated process.

If a store wants to honor the promotions they gave the customer at time of purchase or recalculate them should be up to the individual store.

Taxes are recalculated and records adjusted once the admin user is done making changes to the order. An automated refresh cannot predict when a good time to do that is.

rhovland’s picture

Updated patch for latest version of module