Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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>'
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement