assets/js/theme/common/product-details.js
/**
     *
     * Handle action when the shopper clicks on + / - for quantity
     *
     */
Handle action when the shopper clicks on + / - for quantity
Handle action when the shopper clicks on + / - for quantity
listenQuantityChange() {
        this.$scope.on('click', '[data-quantity-change] button', event => {
            event.preventDefault();
            const $target = $(event.currentTarget);
            const viewModel = this.getViewModel(this.$scope);
            const $input = viewModel.quantity.$input;
            const quantityMin = parseInt($input.data('quantityMin'), 10);
            const quantityMax = parseInt($input.data('quantityMax'), 10);
            let qty = parseInt($input.val(), 10);
            if ($target.data('action') === 'inc') {
                if (quantityMax > 0) {
                    if ((qty + 1) <= quantityMax) {
                        qty++;
                    }
                } else {
                    qty++;
                }
            } else if (qty > 1) {
                if (quantityMin > 0) {
                    if ((qty - 1) >= quantityMin) {
                        qty--;
                    }
                } else {
                    qty--;
                }
            }
            viewModel.quantity.$input.val(qty);
            viewModel.quantity.$text.text(qty);
        });
    }
listenQuantityChange ( ) { this . $scope . on ( 'click' , '[data-quantity-change] button' , event => { event . preventDefault ( ) ; const $target = $ ( event . currentTarget ) ; const viewModel = this . getViewModel ( this . $scope ) ; const $input = viewModel . quantity . $input ; const quantityMin = parseInt ( $input . data ( 'quantityMin' ) , 10 ) ; const quantityMax = parseInt ( $input . data ( 'quantityMax' ) , 10 ) ; let qty = parseInt ( $input . val ( ) , 10 ) ; if ( $target . data ( 'action' ) === 'inc' ) { if ( quantityMax > 0 ) { if ( ( qty + 1 ) <= quantityMax ) { qty ++ ; } } else { qty ++ ; } } else if ( qty > 1 ) { if ( quantityMin > 0 ) { if ( ( qty - 1 ) >= quantityMin ) { qty -- ; } } else { qty -- ; } } viewModel . quantity . $input . val ( qty ) ; viewModel . quantity . $text . text ( qty ) ; } ) ; }
Handle action when the shopper clicks on + / - for quantity
Handle action when the shopper clicks on + / - for quantity
// If action is incrementing // If quantity max option is set // Check quantity does not exceed max // If quantity min option is set // Check quantity does not fall below min // update hidden input // update text