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/blijegasten/blijegasten.be/resources/js/shop/components/productController.js
/**
 * Product controller.
 */
class ProductController {
    /**
     * @param {ShoppingcartService} shoppingcartService
     */
    constructor(shoppingcartService) {

        this.productPageModel = document.querySelector('.js-add-product');

        if(!isset(this.productPageModel)) return;

        this.addProductButton = this.productPageModel.querySelector('.js-add-product-button');
        this.productQuantityInput = this.productPageModel.querySelector('.js-add-product-quantity');

        this.shoppingcartService = shoppingcartService;
        if (!shoppingcartService) {
            console.error('ShoppingCartController: The shoppingCartController was expected to get an instance of ShoppingcartService, but did not get one.');
            return;
        }

        this.addProductEvent = this.addProductEvent.bind(this);
        this.productQuantityInputChanged = this.productQuantityInputChanged.bind(this);

        this.addProductButton.addEventListener('click', this.addProductEvent);
        this.productQuantityInput.addEventListener('change', this.productQuantityInputChanged);
    }

    addProductEvent(event)
    {
        const productId = this.productPageModel.dataset.productId;
        const productType = this.productPageModel.dataset.productType;

        this.shoppingcartService.validateProductQuantityInput(this.productQuantityInput);
        this.shoppingcartService._addProductToShoppingcart(productId, productType, parseInt(this.productQuantityInput.value));
    }

    productQuantityInputChanged(event)
    {
        this.shoppingcartService.validateProductQuantityInput(event.currentTarget);
    }

}

export {ProductController}