Created
July 27, 2017 19:20
-
-
Save okwme/afb238d3ee6155e41d95d3647ae5d084 to your computer and use it in GitHub Desktop.
Using Shopify's JS Buy SDK with the Back In Stock App outside of Shopify's Store Front
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var processedProducts = [] | |
var shopClient = ShopifyBuy.buildClient({ | |
accessToken: 'your-access-token', | |
domain: 'your-shop-subdomain.myshopify.com', | |
appId: '6' | |
}) | |
shopClient.fetchAllProducts().then((products) => { | |
processedProducts = products.map((product) => { | |
var item = product.attrs | |
item.id = item.product_id | |
item.CONTAINS_OUT_OF_STOCK_ITEM = false | |
for (var i = 0; i < item.variants.length; i++) { | |
var variant = item.variants[i] | |
if (!variant.available) { | |
item.CONTAINS_OUT_OF_STOCK_ITEM = true | |
variant.inventory_quantity = 0 | |
} | |
variant.inventory_management = 'shopify' | |
variant.option_values.map((option, index) => { | |
variant['option' + (index + 1)] = option.value | |
return option.value | |
}) | |
variant.option = variant.option_values | |
item.variants[i] = variant | |
} | |
// Back in stock will only trigger if the item is unavailable | |
// status of item also available under item.CONTAINS_OUT_OF_STOCK_ITEM | |
return '<a class="BIS_trigger" data-product-data="' + JSON.stringify(item) + '" href="#">' + item.title + '</a>' | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment