Skip to content
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

Fix duplicate product endpoint args for item schema #46551

Merged
merged 3 commits into from Apr 16, 2024

Conversation

octaedro
Copy link
Contributor

@octaedro octaedro commented Apr 12, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR fixes an error related to the duplicate product REST API endpoint. The method was working well but it did not duplicate the stock management option.

That was happening because we sent the wrong param to get_endpoint_args_for_item_schema.
This PR adds some unit tests and fixes the bug.

Product type and status are not editable.

Closes #46535.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Create a simple and a variable product and write down their IDs. In the case of the variable product, set a price for all the variations.
  2. Install this plugin and activate it.
  3. The plugin will show two buttons, Duplicate and Duplicate and modify. After pressing any of them, a prompt asking for a Product ID to duplicate will be visible. After adding a product ID and pressing ok, it will send a request to /wp-json/wc/v3/products/[your-product-id]/duplicate.
  4. Open the browser's dev tools and go to the Console tab.
  5. Press Duplicate and add the ID of the simple product to the prompt. If everything goes well you'll see the duplicated product printed in the console.
  6. Verify that the new product has:
  • A new ID
  • The product's name says (Copy) at the end
  • The product status is Draft.
  1. You can also go to Products > All Products and find the duplicated product there.
  2. Repeat step 5 with the variable product ID.
  3. Select the duplicated product from Products > All Products. Verify that the variations were duplicated correctly (the prices set in step 1 should match).
  4. Now press Duplicate and modify and add the ID of the simple product to the prompt. If everything goes well you'll see the duplicated product printed in the console. This option also sends a description of the product, so the duplicated product's description should say: "This is my description".
  5. Repeat step 10 with a variable product.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Apr 12, 2024
@woocommercebot woocommercebot requested review from a team and jorgeatorres and removed request for a team April 12, 2024 18:41
Copy link
Contributor

github-actions bot commented Apr 12, 2024

Hi @jorgeatorres, @woocommerce/mothra

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

@octaedro octaedro changed the title Fix/46535 duplicate product stock management Fix duplicate product endpoint args for item schema Apr 12, 2024
@octaedro octaedro self-assigned this Apr 12, 2024
@octaedro octaedro requested a review from a team April 12, 2024 19:02
@octaedro octaedro added team: Mothra focus: new product ux revamped product management experience labels Apr 12, 2024
@octaedro octaedro marked this pull request as ready for review April 12, 2024 19:02
@octaedro octaedro removed the request for review from jorgeatorres April 12, 2024 19:03
@@ -99,10 +99,6 @@ public function duplicate_product( $request ) {
return new WP_Error( 'woocommerce_rest_product_invalid_id', __( 'Invalid product ID.', 'woocommerce' ), array( 'status' => 404 ) );
}

if ( 'simple' !== $product->get_type() ) {
Copy link
Contributor Author

@octaedro octaedro Apr 12, 2024

Choose a reason for hiding this comment

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

I removed this because it's not necessary anymore.

Copy link
Contributor

@mdperez86 mdperez86 left a comment

Choose a reason for hiding this comment

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

LGTM @octaedro nice job!

@octaedro octaedro merged commit 25eafff into trunk Apr 16, 2024
36 checks passed
@octaedro octaedro deleted the fix/46535_duplicate_product_stock_management branch April 16, 2024 14:13
@github-actions github-actions bot added this to the 8.9.0 milestone Apr 16, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Apr 16, 2024
@alopezari alopezari added needs: internal testing Indicates if the PR requires further testing conducted by Solaris status: analysis complete Indicates if a PR has been analysed by Solaris contains: rest api change Indicates if the PR contains a REST API change. and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Apr 16, 2024
nielslange pushed a commit that referenced this pull request Apr 20, 2024
* Fix endpoint args for item schema

* Add tests

* Add changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contains: rest api change Indicates if the PR contains a REST API change. focus: new product ux revamped product management experience needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin. status: analysis complete Indicates if a PR has been analysed by Solaris team: Mothra
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Rest endpoint to duplicate product is not duplicating stock management check
3 participants