Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shopifypartners/464d4d80c8b64b916ec504dceeee3e2a to your computer and use it in GitHub Desktop.
Save shopifypartners/464d4d80c8b64b916ec504dceeee3e2a 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