Created
December 14, 2018 07:41
-
-
Save stefbowerman/9e9678d470fc7e9b3cdbb7b5c8114966 to your computer and use it in GitHub Desktop.
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
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