File: D:/HostingSpaces/SBogers10/shop.komma.nl/resources/js/services/shoppingCartService.js
import { axios } from '../../../vendor/komma/kms/resources/js/global/axiosBootstrapper';
class ShoppingCartService
{
constructor()
{
this.baseRoute = '/';
}
/**
* Adds a product to the shopping cart
*
* @param id
* @param productableEnum
* @param quantity
* @return {Promise}
*/
addProductToShoppingcart(id, productableEnum, quantity) {
return axios.post(
this.baseRoute+'addProductToShoppingcart',
{productableId: id, productableEnum: productableEnum, quantity: quantity || 1}
);
};
/**
* Remove a product from the shopping cart
*
* @param id
* @return {Promise}
*/
removeItemFromShoppingcart(id) {
return axios.post(
this.baseRoute+'removeItemFromShoppingcart',
{itemId: id}
);
};
/**
* Set the quantity of a shopping cart item
*
* @param id
* @param quantity
* @return {Promise}
*/
setItemQuantityInShoppingcart(id, quantity) {
if (quantity > 0) {
return axios.post(
'/setItemQuantityInShoppingcart',
{itemId: id, quantity: quantity}
);
} else {
return this.removeItemFromShoppingcart(id);
}
}
}
export { ShoppingCartService }