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}