FROM CACHE - en_header
Return management just got easier! We’ve launched Customer Self-Serve Returns to all Shopify merchants. Click here to learn more!

Rest API determine if product has variants or no variants

5 0 5

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.

Replies 2 (2)
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!

Shopify Partner
1 0 0

Does anybody have the answer to this question?