Skip to content

Instantly share code, notes, and snippets.

@richgilbank
Last active March 16, 2016 17:25
Show Gist options
  • Save richgilbank/69c09b4ba46879231a67 to your computer and use it in GitHub Desktop.
Save richgilbank/69c09b4ba46879231a67 to your computer and use it in GitHub Desktop.
js-buy-api
var shopClient = ShopifyBuy.buildClient({
appId: '',
apiKey: '',
myShopifyDomain: ''
});
// Fetching one product
shopClient.fetchProduct(123).then(function(product) {
// => product
// product.selectedVariant.checkoutUrl({quantity: 1});
})
// Fetching the products in a collection
shopClient.fetchQueryProducts({collection_id: 123}).then(function(products) {
// => [products]
});
var cart;
shopClient.createCart().then(function(remoteCart) {
cart = remoteCart;
});
// once promises are resolved
cart.addVariant({variant: product.selectedVariant, quantity: 1}).then(function(updatedCart) {
document.location.href = cart.checkoutUrl;
});
// cart.updateLineItem({id: 123, quantity: 307});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment