How to update only one Quantity to the cart on the ADD TO CART button for those items which have minimum quantity is set as 25 in NetSuite.

using this method, we can set the quantity 1 for the item which has minimum quantity also.

   getAddToCartValidators: function getAddToCartValidators() {
        const self = this;

        return {
            quantity: {
                fn: function() {
                    const line_on_cart = self.cart.findLine(self.model);
                    const quantity = self.model.get('quantity');
                    const minimum_quantity = self.model.getItem().get('_minimumQuantity') || 1;
                    let maximum_quantity = self.model.getItem().get('_maximumQuantity');

                    if (!_.isNumber(quantity) || _.isNaN(quantity) || quantity < 1) {
                        return Utils.translate('Invalid quantity value');
                    }

                    if (!line_on_cart && quantity < minimum_quantity) {
                        return Utils.translate(
                            'Please add $(0) or more of this item',
                            minimum_quantity
                        );
                    }

                    if (maximum_quantity) {
                        maximum_quantity = !line_on_cart
                            ? maximum_quantity
                            : maximum_quantity - line_on_cart.get('quantity');

                        if (quantity > maximum_quantity) {
                            return Utils.translate(
                                'Please add $(0) or less of this item',
                                maximum_quantity
                            );
                        }
                    }
                }
            }
        };
    },

Leave a comment

Your email address will not be published. Required fields are marked *