getting product/variant information with shopifyapi

New Member
10 0 0

Hi

I have "barcode" of our products, I am trying use the barcode, to find the variant/product  and read price,sku and etc.

commands like this didn't produce anything...

ShopifyAPI::Variant.find(:params =>{:barcode=>"12345678"}) 

Any idea please.

Thanks

Paulo

 

 

0 Likes
Shopify Staff
Shopify Staff
582 0 45

You can't search for variants based on the Barcode. You'll need to keep track of the variant ID and find it that way.

0 Likes
New Member
10 0 0

Thanks,

I found the following query,  posted by you  a while ago, it sometimes works and sometimes doesn't... (meaning sometimes it returns result, sometimes it returns "nil")

since I don't see  any error msg, I really don't know why it doesn't work sometimes..

any suggestion to improve this:  (Thanks)

variants = ShopifyAPI::Variant.find(:all, query: {fields: %w(id sku inventory_quantity).join(',')})
variant = variants.detect { |v| v.barcode == "1234AAAA" }

0 Likes
Highlighted
Shopify Staff
Shopify Staff
582 0 45

It's returning nil because it's not detecting anything from that collection. If you have more than 50 variants, :all won't return everything, just the first page.

You'll need to go out and fetch all your variants, then do the search over those.

0 Likes
New Member
10 0 0

Oh I see ... thanks,

 

 

0 Likes