-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Fix stock status saving for variable products on bulk and quick edit #26174
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
vedanshujain
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 work! Overall its looking pretty good and nice job in refactoring some messy logic! I have left some comments, but mostly they nitpick and code is testing well.
|
I've removed that unnecessary |
|
@vedanshujain Could you go through the comments above and clear the resolved items? |
vedanshujain
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.
Changes look great and are testing well!! I have left a few comments, most of them are not blockers but one needs to be addressed before we can merge.
…min_Post_Types. Two methods have been created: - update_stock_status, replaces code that was duplicated in the quick_edit_save and bulk_edit_save methods. - set_new_price, replaces code that was duplicated-ish in the bulk_edit_save for setting the new regular and sales prices (code was not identical but very similar). Also, `round` is now used on sale price calculations that involve multiplying by a percent, the same was as it was done already to calculate the regular price.
For bulk edit: even if stock status was left as "No change", the status of all variations was being changed to whatever the status of the product was before it was converted to variable. Now no change is performed when "No change" is selected, and all variations change to whatever is selected otherwise. For quick edit: a new "No change" option is added that will be preselected when the product is variable. Previously, whatever status the product had before being converted to variable was being shown, and that's the status that would be set when saving. Also, a "This will change the stock status of all variations" message is displayed before the selector.
Create a new `request_data` method in WC_Admin_Post_Types that just returns $_REQUEST. This is intended to ease unit testing, as this method can be easily mocked to return test data.
Those methods are a convenient replacement for "this->factory->user->create". Tests that were using that to simulate user login have been modified to use the new methods.
The test added checks that stock status of variations when saving a variable product is changed or not appropriately depending on the request data supplied.
…tus_for_variable_product. At some point the 'change_stock' key is assumed to be present in the request data, but it might not. Fixed to test for existence before using the value.
Add a new optional $props parameter containing the properties to be set in the newly created product.
The test added checks that the new regular or sale price is appropriately set when bulk saving.
- Remove no longer needed phpcs disablers. - Rename method. - Remove no longer needed logic. - Simplify some logic.
vedanshujain
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.
LGTM!
claudiosanches
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.
Works great!
All Submissions:
Changes proposed in this Pull Request:
Fixes related to stock status for variable products on bulk and quick edit.
For bulk edit: Even if stock status was left as "No change", the status of all variations was being changed to whatever the status of the product was before it was converted to variable. Now no change is performed when "No change" is selected, and all variations change to whatever is selected otherwise.
For quick edit: A new "No change" option is added to the "Stock status" selector that will be preselected when the product is variable. Previously, whatever status the product had before being converted to variable was being shown, and that's the status that would be set when saving. Also, a "This will change the stock status of all variations" message is displayed before the selector.
Other improvements introduced:
WC_Unit_Test_Caseclass gets two new utility methods:login_as_roleandlogin_as_administrator.WC_Helper_Product::create_simple_productgets a new optional$propsargument.Closes #25843.
How to test the changes in this Pull Request:
Other information:
Changelog entry