Skip to content

Conversation

@Konamiman
Copy link
Contributor

@Konamiman Konamiman commented Apr 14, 2020

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.

image

Other improvements introduced:

  • WC_Unit_Test_Case class gets two new utility methods: login_as_role and login_as_administrator.

  • WC_Helper_Product::create_simple_product gets a new optional $props argument.

Closes #25843.

How to test the changes in this Pull Request:

  1. Create a variable product with two variations. Set stock status to "Out of stock" for one of them and to "On backorder" for the other.
  2. Bulk edit the product, don't change anything and save. Verify that the stock status of the variations hasn't changed (without the fix, both would have changed to "In stock").
  3. Bulk edit the product again, se the stock status selector to "In stock" and save. Verify that this time the status of both variations has changed.
  4. Change the stock status of both variations to anything but "In stock" again.
  5. Quick edit the product. Verify that the preselected value for the stock status selector is now "No change". Leave it that way and save. Verify that the stock status of the variations hasn't changed.
  6. Quick edit the product again. Select "In stock" in the stock status selector. Verify that this time the status of both variations has changed.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Changelog entry

Fix - don' change the stock status of variations when bulk editing a variable product and leaving the "Stock status" selector as "No change".
Enhancement - Add a "No change" option to the "Stock status" selector in quick edit, preselect it when the product being edited is a variable product.

@Konamiman Konamiman added Bug The issue is a confirmed bug. status: needs review labels Apr 14, 2020
@Konamiman Konamiman self-assigned this Apr 14, 2020
@Konamiman Konamiman added status: needs review and removed status: in progress This is being worked on. labels Apr 16, 2020
@Konamiman Konamiman marked this pull request as ready for review April 17, 2020 14:57
Copy link
Contributor

@vedanshujain vedanshujain left a 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.

@Konamiman
Copy link
Contributor Author

I've removed that unnecessary //phpcs:ignore. @claudiosanches @vedanshujain could you plz review this again?

@rrennick
Copy link
Contributor

rrennick commented Jul 7, 2020

@vedanshujain Could you go through the comments above and clear the resolved items?

@vedanshujain vedanshujain self-requested a review July 13, 2020 14:26
Copy link
Contributor

@vedanshujain vedanshujain left a 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.

Konamiman added 10 commits July 14, 2020 11:42
…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.
Copy link
Contributor

@vedanshujain vedanshujain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@claudiosanches claudiosanches left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great!

@claudiosanches claudiosanches merged commit aafb069 into master Jul 24, 2020
@claudiosanches claudiosanches deleted the fix/25843 branch July 24, 2020 20:05
@woocommercebot woocommercebot added release: add changelog Mark all PRs that have not had their changelog entries added. [auto] release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto] labels Jul 24, 2020
@claudiosanches claudiosanches added this to the 4.4.0 milestone Jul 24, 2020
@Konamiman Konamiman removed status: approved release: add changelog Mark all PRs that have not had their changelog entries added. [auto] labels Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug The issue is a confirmed bug. release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bulk Edit Variation -no change- changes "Out of Stock" variation to "In Stock", oops.

6 participants