-
-
Save richgilbank/69c09b4ba46879231a67 to your computer and use it in GitHub Desktop.
js-buy-api
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 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