FROM CACHE - en_header

Rest API determine if product has variants or no variants

cmuench
Tourist
5 0 3

I understand in the Shopify api a product will always have 1 variant even if the end user doesn't setup variations in the admin panel. I need to be able to detect if the product coming back from rest API has 1 real variation OR just the default variation (used when a product does NOT have any variations)

What I am doing now is

//if we have more than 1 variation I know it is using real variations...But if an end user sets up a product with 1 variation I want to detect that also. So I check the title field NOT being Default Title

if (count($result['product']['variants']) > 1 || $result['product']['variants'][0]['title'] != 'Default Title')

This feels really hacky; but there isn't a field in the product rest api I can use.

Reply 1 (1)
Big_Van_Studio1
Shopify Partner
17 0 0

yes.. I have the same problem. I am not sure if the words "Default Title" also works in other locations/languages. I mean, has a Chinese store the same "Default Title" for the default variation?. Not sure of this...

 

Were you able to find a better solution?

 

Thanks in advance!