Skip to content

Instantly share code, notes, and snippets.

@tessalt
Last active February 22, 2017 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tessalt/a9f538f3eb6d9d9ce40f79b6ece4aa5f to your computer and use it in GitHub Desktop.
Save tessalt/a9f538f3eb6d9d9ce40f79b6ece4aa5f to your computer and use it in GitHub Desktop.
<ul id="products"></ul>
<input id="product_id" name="product_id" type="text" />
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