Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. var processedProducts = []
  2.  
  3. var shopClient = ShopifyBuy.buildClient({
  4. accessToken: 'your-access-token',
  5. domain: 'your-shop-subdomain.myshopify.com',
  6. appId: '6'
  7. })
  8.  
  9. shopClient.fetchAllProducts().then((products) => {
  10. processedProducts = products.map((product) => {
  11. var item = product.attrs
  12. item.id = item.product_id
  13. item.CONTAINS_OUT_OF_STOCK_ITEM = false
  14.  
  15. for (var i = 0; i < item.variants.length; i++) {
  16. var variant = item.variants[i]
  17. if (!variant.available) {
  18. item.CONTAINS_OUT_OF_STOCK_ITEM = true
  19. variant.inventory_quantity = 0
  20. }
  21. variant.inventory_management = 'shopify'
  22. variant.option_values.map((option, index) => {
  23. variant['option' + (index + 1)] = option.value
  24. return option.value
  25. })
  26. variant.option = variant.option_values
  27. item.variants[i] = variant
  28. }
  29. // Back in stock will only trigger if the item is unavailable
  30. // status of item also available under item.CONTAINS_OUT_OF_STOCK_ITEM
  31. return '<a class="BIS_trigger" data-product-data="' + JSON.stringify(item) + '" href="#">' + item.title + '</a>'
  32. })
  33. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement