I'm using (http://localhost/store-api/product/{productId}) this endpoint to fetch the specific product of shopware 6 by passing productId
. I have to change the product variant when I click on the properties of the product.
I tried to get the product id with different way but can't. How can I change the product?
By default this should already happen. Is there a reason specific you chose not to use the existing functionality of variants and switching thereof and to rebuild it instead?
Anyway, you can retrieve the id of a variant by the set of corresponding option properties. To do so there's a route of the storefront you can use.
parentId
is the id of the parent of the currently viewed product:product.parentId
options
is a url encoded json object with key value pairs of property group id to property option id of all property options assigned to the variant, that you want to get the id of.Example for your case:
Let's say
b1c9a2dddbac43198f32183edc197e61
would be the id of the property group "Size", then739a59b89fd341c6a6d49d349dae56e6
would be the id of the selected size option.If done correctly the response will give you the SEO url and id to the variant associated with the options: