Order Refresh should work for non-draft orders, too

Created on 4 May 2017, almost 7 years ago
Updated 12 February 2024, 12 days ago

In the course of working on our specific business case, as well as integrating with the latest changes in Tax, it appears we need the ability to allow order refresh to occur on non-draft orders, as well. Currently Order module will abort automatic refresh in the default configuration if the order is not a draft. However, it is possible to manually set the refresh state or call the refresh manager directly.

The reasons for doing this vary, but all have to do with responding to changes to the order after it is placed but before it's considered "complete." In our case, this means adjustments during fulfillment (e.g., changes to the actual quantity we can ship) but mglaman points out this relates to backorders and other types of order validation workflow. The goal of refreshing the order is essentially to call order processors, which could for instance re-calculate tax.

The logic in OrderRefresh::refresh() performs other tasks, however, that are destructive to non-drafts. Order item unit prices are re-set (which would appear to be generally undesirable) and the order item's order ID relationship is removed, which is obviously not good. There is a @todo note to "evaluate which order items have changed," which would be more or less what we need to do.

In the short term I have manually triggered tax re-calculation and other processor calls in pre-save hooks, but that isn't a sustainable solution for Commerce Order. What do the maintainers think about this, particularly since it touches some common use-cases like backorder?

One example of an edge case we will need to address: The availability order processor does not pass through the order status to the various availability plugins, only a global Context object. This is rational because there may not actually be an order, yet, but if a product resolves as available only because it's not yet in a placed order, it will be removed during the order refresh because we lack context to decide otherwise.

🌱 Plan
Status

Active

Version

2.0

Component

Order

Created by

πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates : some issue and comment data are missing.

  • πŸ‡¨πŸ‡¦Canada xmacinfo Canada

    Yes, we need some way to refresh the calculation instead of deleting an order and recreating it. It could be a button available only to a user with a specific role.

    In my use case, I created an order and forgot to add the billing information. I placed the order too quickly before checking if everything was fine.

    I edited the order to add the correct billing information, but the taxes won't refresh.

  • πŸ‡ΊπŸ‡ΈUnited States rhovland

    @xmacinfo See the attached child issue. I added a form to refresh taxes
    https://www.drupal.org/project/commerce/issues/3333475 ✨ Provide an administrative taxes page on the order Needs review

  • πŸ‡©πŸ‡ͺGermany M_Z

    I came across this issue and want to report how you can manually trigger an order refresh if you have an order type with shipping.

    On the /admin/commerce/orders/ORDER_ID/shipments tab you can "edit" an existing shipment for your order.
    You can active the checkboxes for all shipment items and then click the "Recalculate shipping" button.
    Don't forget to click the "Save" button at the bottom.

    Afterwards you should see the correct tax values in the order summary on /admin/commerce/orders/ORDER_ID tab.

    This workaround-like solution should work for a shop administrator with proper permissions.

    ------

    (For developers you can use devel_php or a custom module to execute the following code for the $order entity that should be refreshed:

    $orderRefresh = \Drupal::service('commerce_order.order_refresh');
    $orderRefresh->refresh($order);
    

    But this solution isn't suitable for a typical shop administrator, so I want to share my shipping refresh solution above.)

Production build https://api.contrib.social 0.61.6-2-g546bc20