Combining type=variation
with attributes
for Store API /products
endpoint doesn't work
#42093
Labels
type=variation
with attributes
for Store API /products
endpoint doesn't work
#42093
Describe the bug
The
/products
endpoint accepts the parametertype=variation
, which returns product variations, instead of products.An example request:
/wp-json/wc/store/v1/products?type=variation&parent=24958&attributes[0][attribute]=pa_size&attributes[0][slug]=44
However, when combining
type=variation
with theattributes
parameter, the query becomes incorrect. The example I provided should return all variations that have the product attribute termpa_size
44
, with parent product ID24958
.However, instead it returns no variations when using the
attributes
parameter in combination withtype=variation
, since the resulting query is incorrect.https://github.com/woocommerce/woocommerce-blocks/blob/trunk/src/StoreApi/docs/products.md#product-variations
https://github.com/woocommerce/woocommerce-blocks/blob/trunk/src/StoreApi/docs/products.md#list-products
Expected behavior
When using
type=variation
and theattributes
parameter, it should return all variations that have those attribute terms.For example, this query would work (for the example URL provided) - since attribute terms linked to variations are stored in the
wp_postmeta
table for variations:While it currently results in this query (which only works for products, not variations):
Though an issue that arises is that only the
slug
is stored for variation attribute terms inwp_postmeta
asmeta_value
, and not theterm_id
, which is supported for theattributes
parameter.My knowledge of the internals of WooCommerce isn't good enough to figure out a better solution. E.g. maybe the
wc_product_attributes_lookup
table?Screenshots
Environment
WordPress:
The text was updated successfully, but these errors were encountered: