HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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 }