We're using order processors to add shipping and tax charges. This runs on the order refresh process. We're noticing issues where a user could quickly add an item to the cart and reach checkout before a second refresh runs within the 30-second threshold. This is causing stale data.

Cart Manager should invoke a refresh of the cart when an order item is added, deleted, or updated.

CommentFileSizeAuthor
#2 cart_manager_needs_to-2813583-2.patch3.93 KBmglaman

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
StatusFileSize
new3.93 KB

Patch

mglaman’s picture

mglaman’s picture

Fixing attribution.

bojanz’s picture

I think our code is going to become messy if we start injecting the order refresh service to every place that modifies an order.
Instead, we can introduce $order->needsRefresh() that sets $order->data['needs_refresh'], and listen for that in a presave callback?

mglaman’s picture

Title: Cart manager needs to refresh orders explicitly when order items change » Orders must able to be flagged for refresh on save.
Status: Needs review » Needs work

We need a way to let an order know it should refresh the next time it saves.

bojanz’s picture

Title: Orders must able to be flagged for refresh on save. » Expand the order refresh logic

We need:

1) A needs_refresh flag for $order->data that always triggers a refresh
2) An order method for requesting a refresh
3) Logic that triggers a refresh despite the order frequency if the day has changed
4) To increase the default order frequency (to 5min)
5) To add a docblock for refreshingOrders, and make it non-static (the container always gives us a single class instance)

Tests.
Might be time to introduce and inject a Time object (with a now()) method, to be able to efficiently test #3.
Would also be super convenient for recurring.

bojanz’s picture

Status: Needs work » Needs review

  • bojanz committed 1f2ab8e on 8.x-2.x
    Issue #2813583 by mglaman, bojanz: Expand the order refresh logic
    
bojanz’s picture

Priority: Normal » Major
Status: Needs review » Fixed

Refresh now happens on presave, with the option of postponing it to the next load, or skipping it altogether.
Unless skipped, refresh is always triggered automatically for draft orders.
Changed the default order type's refresh mode to "customer" (to match Commerce 1.x), increased refresh frequency to 5min.

API changes:
- Added getRefreshState() and setRefreshState() to orders.
- Added a guarantee that order refresh frequency is always at least 1s, used it to remove the static from OrderRefresh
- Improved the order refresh frequency form element (OrderTypeForm)
- Added logic that always refreshes if the day has changed.
- Split needsRefresh into needsRefresh and shouldRefresh. Allows us to show a message to the admin saying "looks like this order needs to be refreshed, would you like to do that?"
- Rewrote the order refresh tests.
- Fixed bug where order items were saved before the processors had a chance to modify them.
- Fixed wrong typehint for $current_user.
- Copied the Drupal 8.3.x Time object into Commerce, added it to the refresh process.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.