Js-buy-sdk: Inventory count under product variant model

Created on 16 Aug 2016  路  10Comments  路  Source: Shopify/js-buy-sdk

It already can return values such as price and variant image. For my purposes being able to access the current inventory count based on the selected variant would be helpful. Any thoughts?

Most helpful comment

Is there anyway Shopify could return the quantity of items left? Rather than just "available." It's nice that when you go to checkout URL it corrects your order, but it would be nice if I could adjust my user interface based on quantity left.

All 10 comments

I tried using the available method but kept receiving undefined even though variables such as id, price, etc. work. Either way a function that returns the actual inventory count would be useful.

/**
* Variant in stock (always true if inventory tracking is disabled)
* @property available
* @type {Boolean}
*/
get available() {
return this.attrs.variant.available;
},

Hey @tdetweiler.

Can you confirm you are using v0.2.2? That's when variant.available was added

I'm including the api via script src="http://sdks.shopifycdn.com/js-buy-sdk/latest/shopify-buy.polyfilled.globals.min.js" which is listing the source as 0.2.1

Unless there's a new way to get the updated version?

Hey @yomexzo

Any follow up on this? Is the latest .js going to be upgraded to 2.2 or is there another src href I can use?

Hi @tdetweiler, we don't currently expose the inventory counts for product variants in our public API, only the given available attribute. Do you have a specific need around that?

For better customer experience being able to display/limit the quantity added to the cart before sending the user to the shopify checkout would be nice (ex: showing stock counts if product is <10).

However, the is available attribute would still be a large improvement and stop users from adding a product only to find out it's unavailable when they attempt to checkout. As mentioned though this is not working and doesn't seem available with the current javascript as documented on http://shopify.github.io/js-buy-sdk/

Understood, we'll try to get the corrected version up with available working and let you know.

hey @tdetweiler,

wanted to let you know http://sdks.shopifycdn.com/js-buy-sdk/latest/shopify-buy.polyfilled.globals.min.js now has v0.2.2 which has the available attribute you need.

Let us know how it goes.

Cheers.

Is there anyway Shopify could return the quantity of items left? Rather than just "available." It's nice that when you go to checkout URL it corrects your order, but it would be nice if I could adjust my user interface based on quantity left.

Sorry forgot to come back and comment. available attribute worked and was successfully implemented. Thanks!

Was this page helpful?
0 / 5 - 0 ratings