When variants are changing on the page dynamically I need to detect the featured media id. Originally I was doing this by looping through all variants but now we get only 250 variants. How can I fetch the featured media id if I I have a variant id?
Input: Variant id
Output: featured media id
productLiquid.variants.forEach(variant => {
if (variant.id === theLatestVariantId) {
featuredMediaId = variant.featured_media?.id;
condole.log("Featured media ID changed:", featuredMediaId);
}
});
I also have the same issue. Besides the feature image, how can I get the variant price? I used to load all variants with {{ product.variants }} in liquid. Then I get the selected variant on the client side.
I thought the product URL with option values: GET /products/pants-green?option_values=<option_value_id_1>,…,<option_value_id_N> as mentioned in Granular option value selection for product URLs. But this endpoint only returns the HTML? I want the selected variant in json.