-
-
Save tessalt/a9f538f3eb6d9d9ce40f79b6ece4aa5f to your computer and use it in GitHub Desktop.
This file contains 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
<ul id="products"></ul> | |
<input id="product_id" name="product_id" type="text" /> |
This file contains 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 client = ShopifyBuy.buildClient({ | |
apiKey: '', | |
domain: 'example.myshopify.com', | |
appId: '6' | |
}); | |
var $products = $('#products'); | |
var $input = $('#product_id') | |
client.fetchAllProducts().then(function(products) { | |
products.forEach(function (product) { | |
var li = $('<li>'); | |
li.text(product.title); | |
if (product.selectedVariantImage) { | |
var img = $('<img width="50">'); | |
img.attr('src', product.selectedVariantImage.src) | |
} | |
li.prepend(img); | |
li.click(function (evt) { | |
$input.val(product.id); | |
}); | |
$products.append(li); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment