Recent Topics

Add products in cart with numeric value



  • How can I add products in cart with numeric value? From example cart page



  • 
                data: function() {
                    return {
                        qty: this.quantity
                    }
                },
    
                watch: {
                    quantity: function (val) {
                        this.qty = val;
    
                        this.$emit('onQtyUpdated', this.qty)
    
                        console.log(this.qty)
                    }
                },
    
                methods: {
                    decreaseQty: function() {
                        if (this.qty > this.minQuantity)
                            this.qty = parseInt(this.qty) - 1;
    
                        this.$emit('onQtyUpdated', this.qty)
    
                        console.log(this.qty)
                    },
    
                    increaseQty: function() {
                        this.qty = parseInt(this.qty) + 1;
    
                        this.$emit('onQtyUpdated', this.qty)
    
                        console.log(this.qty)
                    }
                }
    

    For example, how could I make these values receive the data I type from the keyboard?

    <script type="text/x-template" id="quantity-changer-template">
        <div :class="`quantity control-group ${errors.has(controlName) ? 'has-error' : ''}`">
            <label class="required">{{ __('shop::app.products.quantity') }}</label>
            <button type="button" class="decrease" @click="decreaseQty()">-</button>
    
            <input
                :value="qty"
                class="control"
                :name="controlName"
                :v-validate="validations"
                data-vv-as="&quot;{{ __('shop::app.products.quantity') }}&quot;"
                />
    
            <button type="button" class="increase" @click="increaseQty()">+</button>
    
            <span class="control-error" v-if="errors.has(controlName)">@{{ errors.first(controlName) }}</span>
        </div>
    </script>
    
    
    

    Without :value=qty can send data from keyboard but increase and decrease.. will not work


Log in to reply