-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Limit stock changes for order items to status methods for consistency. #26642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } | ||
|
|
||
| $response = array(); | ||
| if ( ! isset( $_POST['order_id'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to reviewer: I have refactored this method in two to add maybe_add_order_item so that I can unit test this better. Only real changes are deletion of these lines: https://github.com/woocommerce/woocommerce/pull/26642/files#diff-133db5662c51f5686d87611121a05a3bL918-L923. Other changes are rearranging of some lines to make unit testing easier.
rrennick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vedanshujain Thanks for getting this one. Looks good. Approving with a note that there are a few PHPCS items reported in class-ajax.php that we should fix:
FILE: includes/class-wc-ajax.php
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
548 | WARNING | [ ] Using the WPCS native whitelist comments is deprecated. Please use the PHPCS native "phpcs:ignore Standard.Category.SniffName.ErrorCode"
| | annotations instead. Found: // WPCS: sanitization ok.
| | (WordPress.Security.ValidatedSanitizedInput.DeprecatedWhitelistCommentFound)
1585 | WARNING | [x] Equals sign not aligned correctly; expected 1 space but found 4 spaces (Generic.Formatting.MultipleStatementAlignment.IncorrectWarning)
1864 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 6 spaces but found 7 spaces
| | (Generic.Formatting.MultipleStatementAlignment.NotSameWarning)
1865 | WARNING | [x] Equals sign not aligned with surrounding assignments; expected 1 space but found 2 spaces
| | (Generic.Formatting.MultipleStatementAlignment.NotSameWarning)
|
Flagging with |
|
When reading more about the background in #21754, it seems to me that this solution would break workflow for those people, no? (emphasis mine)
The previous change was added explicitly to handle this differently, so I'm a bit unsure if this should go in as is. Thus moving back to |
|
@peterfabian This PR still preserves the changes introduced in #22329 (as a response to #21754), with the caveat that, to reduce stock:
We can change this to remove caveat 2, and make sure that stock is reduced as soon as you save the order in any status. However, I would recommend against it so that order status and stock reduction logic is consistent and easier to understand for all our users. For example, in the current master, stocks are reduced if you create an order with payment-pending status. However, if you move the status to In any case, we have to wait till order is saved to reduce the stock, otherwise, there is no way to recover this stock change. |
Methods `wc_maybe_increase_stock_levels` and `wc_maybe_reduce_stock_levels` already reduce/increase stock levels when statuses are changed, so no need to do this here.
|
@peterfabian Do you have any followup on this one? |
peterfabian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great fix, I agree that it should work fine, we just need to highlight it in the release post, as it changes the workflow for some people.
Also, as per comments, the testing instructions should also include on-hold status that can be used when waiting for payment from the end customer.
In #26642 we removed adding reduced_stock meta when adding new order item to prevent ghost entries, but in inadvertently exposed an underlying bug where _reduced_stock meta was getting set to 0 if its emtpy. We were then checking the presence of this meta, but also not reducing the stock in case it was not set.
All Submissions:
Changes proposed in this Pull Request:
Stock changes should be applied only when changing statuses.
Note that this means if a plugin/extension is reducing/adding stock on completed orders, then they would have to also call
wc_maybe_adjust_line_item_product_stockmanually.Closes #26607.
How to test the changes in this Pull Request:
processingorcompletedstatus.Other information:
Changelog entry