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

Get variations by sku #31370

Closed
maxim-skuvault opened this issue Aug 14, 2019 · 16 comments
Closed

Get variations by sku #31370

maxim-skuvault opened this issue Aug 14, 2019 · 16 comments
Assignees
Labels
focus: rest api Issues related to WooCommerce REST API. focus: variation Issues related to product variations. plugin: woocommerce Issues related to the WooCommerce Core plugin. priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. team: Proton WC Core development and maintenance type: enhancement The issue is a request for an enhancement.

Comments

@maxim-skuvault
Copy link

It would be very useful to have an endpoint to get variations by sku, without having so supply the productId.

We use the sku to look up variations in WooCommerce and then update the stock quantity. Currently, to get a variation from the api, the only option is to pass the parent productId, which we don't have nor do we want to keep track of outside wooCommerce. This severely limits the usefulness of the api for the purpose of updating quantities. We're having to get all products and then all variations for each product and then filter variations by sku, which is a huge performance hit

@claudiosanches claudiosanches transferred this issue from woocommerce/wc-api-dev Oct 4, 2019
@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label type: feature request to this issue, with a confidence of 0.93. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@vedanshujain
Copy link
Contributor

This is supported by using sku param to filter the product list. For egs, if you'd like to get a product with sku test_123 the request can be written like so:
/wp-json/wc/v3/products?sku=pro-123

Similarly sku filter is also supported for product variations as well. However, you would still need to do at least one request with sku filter to get product id, then another to get to the variations. But this should be lot faster than getting all the products and then parsing through to get to the variation.

That said, I am closing the issue because we likely won't support endpoints with sku embedded instead of id since the above workaround is probably good enough for the majority of uses. But feel free to write back if that's not the case and this can be discussed further.

@yordivd
Copy link

yordivd commented May 23, 2021

@vedanshujain I really don't understand your answer.
We have 1000's products with each +-6 variations.
Every variation has an unique sku which is printed on a barcode.

E.g.:
Product sku: 5876
Product variations sku: 26298, 16156, 16616

When you make a POS and you want to scan the barcode you can scan this sku code to retrieve the product/variation.
So i scan the product variation with sku 16156... now how can my POS efficiently get this product variation? Since it always needs the parent sku to search variations, but it doesn't know this when scanning the barcode.

I can not wrap my head around why the woocommerce dev team does not see the issue in this. Or am i missing something here?
You are basically saying: if you need to search variations you should sync all products to your own local database to be able to work with it/search in it.

@jorgemd24
Copy link
Contributor

You can use /wp-json/wc/v3/products?sku=variation_sku to get the variation id and the parent_id (product_id)

@diickens
Copy link

@jorgemd24 When I try to get the variation with this endpoint, I get a critical Error response from the server.
When I try this endpoint for the parent product it works perfect. Any Idea?

@maxim-skuvault
Copy link
Author

@jorgemd24, You posted:

You can use /wp-json/wc/v3/products?sku=variation_sku to get the variation id and the parent_id (product_id)

Has this worked for you? When I created this issue the /wp-json/wc/v3/products endpoint would only search by the product sku, not variation sku (what I need). The documentation still implies that it's only by product sku: "sku: Limit result set to products with a specific SKU"

@jorgemd24
Copy link
Contributor

@maxim-skuvault

Has this worked for you?

Yes it does work, have you tried it recently?

sku: Limit result set to products with a specific SKU

I think they are talking "in the broad sense" of products (parent products, variations, simple products, groups etc). Otherwise they will need to specify that only works for parent products or simple products.

@jorgemd24
Copy link
Contributor

@diickens

I get a critical Error response from the server.

Do you have more information about the error? have you tried to debug it?

@vedanshujain vedanshujain reopened this Dec 6, 2021
@vedanshujain vedanshujain transferred this issue from woocommerce/woocommerce-rest-api Dec 6, 2021
@juliaamosova
Copy link
Contributor

Hi @maxim-skuvault,

Thank you for opening the issue! It requires further feedback from the WooCommerce Core team. I am adding the needs developer feedback label to this issue so that the Core team could take a look.

Please note it may take a few days for them to get to this issue. Thank you for your patience.

@juliaamosova juliaamosova added the needs: developer feedback Issues that need feedback from one of the WooCommerce Core developers. label Dec 6, 2021
@barryhughes
Copy link
Member

Thanks for the further discussion of this issue.

Supporting /wp-json/wc/v3/products?sku=<VARIATION|PRODUCT_SKU> seems like a reasonable enhancement (ie, we can also return variable products in cases where one of its variants has the requested SKU). Marking this as a future enhancement; in the meantime if there are any concerns with this solution please just add a fresh comment.

@barryhughes barryhughes added type: enhancement The issue is a request for an enhancement. priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. and removed needs: developer feedback Issues that need feedback from one of the WooCommerce Core developers. labels Jan 5, 2022
@maxim-skuvault
Copy link
Author

@maxim-skuvault
Copy link
Author

@barryhughes

Supporting /wp-json/wc/v3/products?sku=<VARIATION|PRODUCT_SKU> seems like a reasonable enhancement (ie, we can also return variable products in cases where one of its variants has the requested SKU). Marking this as a future enhancement; in the meantime if there are any concerns with this solution please just add a fresh comment.

Thanks. Yes, this would work for our purposes.

@ObliviousHarmony ObliviousHarmony added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Feb 21, 2022
@yordivd
Copy link

yordivd commented Jul 2, 2022

Is there any progress or feedback on this?

@barryhughes
Copy link
Member

Hi! This is not something we are actively working on at present, as it is a low priority from our perspective. However, we are always interested in contributions from the community—and would be receptive to a pull request.

@hoangtu92
Copy link

Came here for a solution and got none. Such a life :D. I'll leave my solution here to make someone else's life easier. You're welcome

// Modify the rest api to search both product and product variation add_filter("woocommerce_rest_product_object_query", function (array $args){ $args["post_type"] = array( 'product', 'product_variation' ); return $args; }, 10, 1);

@rrennick rrennick added focus: variation Issues related to product variations. focus: rest api Issues related to WooCommerce REST API. team: Proton WC Core development and maintenance labels Dec 5, 2023
@jorgeatorres jorgeatorres self-assigned this Jun 5, 2024
@jorgeatorres
Copy link
Member

Hi everyone! 👋

Filtering the results of /wc/v3/products by SKU (?sku=...) works with product variations too, as indicated above and is supported on v1, v2 and v3. The suggested "fix" above makes me think there's something else going on for those that haven't been able to use this functionality.

I'm going to close this issue as it seemsthis can't be reproduced on a recent version, but feel free to re-open or add any other details if you think we've missed something.

@jorgeatorres jorgeatorres closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: rest api Issues related to WooCommerce REST API. focus: variation Issues related to product variations. plugin: woocommerce Issues related to the WooCommerce Core plugin. priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. team: Proton WC Core development and maintenance type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

No branches or pull requests