Skip to content

Instantly share code, notes, and snippets.

@stefbowerman
Created December 14, 2018 07:41
Show Gist options
  • Save stefbowerman/9e9678d470fc7e9b3cdbb7b5c8114966 to your computer and use it in GitHub Desktop.
Save stefbowerman/9e9678d470fc7e9b3cdbb7b5c8114966 to your computer and use it in GitHub Desktop.
import axios from 'axios';
export default class CartAPI {
constructor() {
}
getCart() {
return axios.get('/cart?view=json')
}
addToCart(id, quantity = 1, properties = {}) {
return axios.post('/cart/add.js', {
id: id,
quantity: quantity,
properties: properties
}).then(() => {
return this.getCart();
});
}
getProduct(handle) {
return axios.get(`/products/${handle}.js`);
}
changeLineItemQuantity(line, qty) {
return axios.post('/cart/change.js', {
quantity: qty,
line: line
}).then(() => {
return this.getCart();
});
}
removeLineItem(line) {
return this.changeLineItemQuantity(line, 0);
}
clearCart() {
return axios.post('/cart/clear.js').then(() => {
return this.getCart();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment