We have strong and deep experience in JavaScript, AJAX, MySQL, HTML, CSS and in PHP etc. As per your requirements, my understanding and assumptions based on my experience, following are the steps I would take when building and correcting your cart is:
1) When user will click on add to cart button and enter total number of items then I will check dynamically that the number of items entered by user should be less than or equal to total number of available items in stack.
2) If this check is true then these items will be add to cart
3) 3) If user have entered wrong number then I will generate a message right after below add to cart button that “The items specify by you is greater than our available stack. Please enter valid amount” or message specified by you is replaced by my quote message.
4) And this message will be displayed using AJAX, mean when this check will become wrong then within a second the message will be displayed and there will be no page loading.
5) After that user will enter correct number of items and that process will be proceed without any inconvenience.
These are my assumptions. If there is something missing from here then you can tell me.
We have much experience like that things and we can handle your problem as your wish.
We have done a lot of industrial work and we understand and implement things better than others. We have done many projects like that.
If you have any question feel free to ask.
Thank you
Tech Developer team