Given:
- An Order Type with Refresh Mode set to "Customer"
- A draft order whose customer uid == 0
- A CLI process that loads the order e.g. search_api
- The CLI process is running as uid == 0 (Which is the default behavior)
Expected result:
The order is NOT refreshed when it is loaded.
Actual result:
The order IS refreshed when loaded.
Details:
This causes inconsistent behavior, as only "anonymous" draft orders are refreshed, but not draft orders associated with a user.
Another inconsistent behavior is if you run the process from the web UX, (again, using search indexing as an example) the administrative user will have a uid > 0, and therefore the anonymous orders will NOT be refreshed when indexing.
While there might be a use case for wanting the order to be refreshed from the CLI, it most likely would expect the behavior to be consistent between both anonymous and non-anonymous draft orders.
I would also posit that we shouldn't refresh order types with RefreshMode == 'Always' during CLI processing either, but am reticent to change the meaning of 'Always'. :)
A side effect of this is that the changed date is updated, extending the window of this draft anonymous order for stale cart purging.
It is a small change to avoid a refresh in this scenario.
Patch to follow.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | do-not-refresh-anonymous-draft-orders-if-not-in-cart-session-3379152-8.patch | 6.63 KB | tomtech |
| #6 | do-not-refresh-anonymous-draft-orders-from-cli-3379152-5.patch | 1.19 KB | tomtech |
Comments
Comment #2
tomtech commentedComment #3
jsacksick commentedProbably a duplicate of #2994377: Race conditions can theoretically change placed orders, feel free to reopen if you think this isn't a duplicate.
Comment #4
jsacksick commentedMaybe the right fix is to copy what 1.x did...
I'm guessing we could check if the customer is anonymous that the current customer can update the order.
Comment #5
jsacksick commentedSo I'm guessing a 2.x equivalent fix could look like the following:
Comment #6
tomtech commentedUpdated patch implementing the suggestion in #3379152-5: Skip Order Refresh on draft anonymous orders on CLI.
Tested and resolves the issue.
While this isn't as performant as just checking the CLI variable, it is more logical, and better matches the logic back in 7.x.
Comment #7
jsacksick commentedLet's test this from
OrderRefreshTest::testShouldRefresh().Comment #8
tomtech commentedAs requested in #7, test steps are added in
OrderRefreshTest::testShouldRefresh().This doesn't actually invoke the
_commerce_cart_order_access, though, which would ensure thatOrderRefreshTest::testShouldRefresh()returns TRUE when the cart is present in thecart_session.CartOrderRefreshTest.phphas been added to the cart module to test those scenarios, both when the anonymous user has the cart in thecart_session(returning TRUE) and when it does not (returning FALSE).Comment #11
jsacksick commentedCommitted, thanks Tom!