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

REST API: Add variation product type to response #47377

Merged
merged 4 commits into from May 16, 2024

Conversation

mattsherman
Copy link
Contributor

@mattsherman mattsherman commented May 10, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR address the need to be able to distinguish the product type of a product variation by adding the following two properties property to the product variation REST API responses:

  • type -- the product type for the variation
  • parent_type -- the product type of the variation's parent

This needs has been identified by third party extension developers when considering how to distinguish product variation types in the context of the new product editor:

Prior to this PR, no type property was returned for product variations, which made it impossible to determine the specific type of variation.

Questions:

  • Is there any reason why the type property was not originally included with product variation responses?
    • This seems harmless to add, but I may be missing historical context.
  • Is the parent_type property addition necessary?
    • In theory, I see no inherent restriction in WooCommerce that would limit all variations of a variable product to be the exact same type, or a variation of a particular type to always have the same parent type, so this seems like a reasonable addition to help further cover different ways of distinguishing variations.
    • But, it does have a potential performance implication...
  • Is the parent_type property addition a performance concern?
    • How can I quantify the performance hit from this?

Update: I removed the parent_type property for now because we do not have an immediate need for it.

How to test the changes in this Pull Request:

  1. Add some variable products with variations.

  2. Install a plugin such as WooCommerce Subscriptions that adds additional variable/variation types.

  3. Using a tool such as Postman, make REST API requests to get variations (REST API doc)

    • REST endpoint for variations: /wp-json/wc/v3/products/<product_id>/variations
  4. Verify that the type and parent_type properties property is correct

    • For Variable Product variations, the type is variation
    • For Variable Subscription variations, the type is subscription_variation

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

@mattsherman mattsherman self-assigned this May 10, 2024
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 10, 2024
Copy link
Contributor

github-actions bot commented May 10, 2024

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@mattsherman mattsherman changed the title Try/rest api product variation type REST API: Add variation product type to response May 13, 2024
@mattsherman mattsherman added focus: rest api Issues related to WooCommerce REST API. contains: rest api change Indicates if the PR contains a REST API change. team: Mothra labels May 13, 2024
@mattsherman mattsherman marked this pull request as ready for review May 13, 2024 15:59
@mattsherman mattsherman requested review from a team and jorgeatorres and removed request for a team May 13, 2024 15:59
Copy link
Contributor

github-actions bot commented May 13, 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

Copy link
Contributor

@nathanss nathanss left a comment

Choose a reason for hiding this comment

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

I've explored a very similar approach locally and it works, I didn't see any regressions and it meets expectations, which is to have a property type which will always be variation for product variations.

@mattsherman mattsherman force-pushed the try/rest-api-product-variation-type branch from aee7f4d to 5ee1cc8 Compare May 15, 2024 20:45
@mattsherman
Copy link
Contributor Author

@woocommerce/proton It would be helpful if somebody on your team could also review this to make sure we aren't overlooking a reason why this wasn't in place originally! Thanks!

Copy link
Member

@jorgeatorres jorgeatorres left a comment

Choose a reason for hiding this comment

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

@mattsherman: Thanks for submitting the PR. We also don't know the context on why this wasn't in place originally, but the change looks good to us.

Would you please mind expanding a bit on the testing instructions before merging? I think it'd be best to explicitly indicate the URL that should be used for the REST part of the test (i.e. /wp-json/wc/v3/products/<product_id>/variations) and confirm that for regular variable products you'll get variation but for Subscriptions variable products you should get subscription_variation.

Thanks again!

@mattsherman
Copy link
Contributor Author

@mattsherman: Thanks for submitting the PR. We also don't know the context on why this wasn't in place originally, but the change looks good to us.

Would you please mind expanding a bit on the testing instructions before merging? I think it'd be best to explicitly indicate the URL that should be used for the REST part of the test (i.e. /wp-json/wc/v3/products/<product_id>/variations) and confirm that for regular variable products you'll get variation but for Subscriptions variable products you should get subscription_variation.

Thanks again!

Thanks for asking for more detailed testing instructions... they were a bit lacking!

@mattsherman mattsherman merged commit d6288e2 into trunk May 16, 2024
25 checks passed
@mattsherman mattsherman deleted the try/rest-api-product-variation-type branch May 16, 2024 15:13
@github-actions github-actions bot added this to the 9.0.0 milestone May 16, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label May 16, 2024
@alvarothomas alvarothomas added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: extensibility contains: rest api change Indicates if the PR contains a REST API change. focus: rest api Issues related to WooCommerce REST API. needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. 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.

None yet

4 participants