0

When user is adding/increasing quantity than how to we can restrict him ? He can't add/increase quantity more than available saleable quantity.

How to we can apply validation for display error message available quantity is not more than this ?

enter image description here

2 Answers 2

0

First find phtml file that's used for quantity input and then fetch saleable quantity for product using product object or as per you get. Once you successfully got product saleable quantity then add that value on quantity input attribute "maxlength" like maxlength="product saleable quantity value" after that user don't able to increase quantity more than available saleable quantity.

I hope this is useful for you.

2
  • I did it as you mentioned but maxlength not working as validation. user can still add more than saleble quantity. Commented Sep 1, 2021 at 11:58
  • Please try only "max" attribute inside of "maxlength" I think it is work for you. also please check you properly got product saleable quantity value. Commented Sep 2, 2021 at 4:50
0

You should use in text form field like :

... class="required-entry validate-digits-range digits-range-1-20"...

This will validate the value to be between 1 and 20.

4
  • can i set this according to saleble quantity of product ? Commented Sep 1, 2021 at 14:04
  • of course, you need to set range dynamically " digits-range-<?php echo minQty.'-.'$maxQty ?>".. Commented Sep 1, 2021 at 14:07
  • digit range is class or attr of html ? Commented Sep 1, 2021 at 14:39
  • Its class name. Commented Sep 1, 2021 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.