J
J
JohnnyBlack2018-01-30 13:23:20
1C-Bitrix
JohnnyBlack, 2018-01-30 13:23:20

How to check for the limit of the quantity of goods when adding to the cart?

Welcome all.
The situation is this: there is a certain amount of goods, let it be 20 pieces. There is an input field in which the desired amount of goods is indicated before being sent to the basket. There are "+" and "-" buttons to adjust this value. The input field has the "text" type, the "+" and "-" buttons work through JS, the number of goods is displayed through $arItem['CATALOG_QUANTITY'].
Question: how to set limits on adding the number of goods to the cart based on their availability? That is, if there are 20pcs. one position, so that a value greater than 20 cannot be passed to the input field.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2018-01-30
@Maksclub

Answer 1: Unload the quantity of goods $arItem['CATALOG_QUANTITY'], for example, in data-attribute and compare the value in the input with it
Answer 2:max Set an attribute with a value directly in the input $arItem['CATALOG_QUANTITY']- htmlbook.ru/html/input/max
but then the type needs to be changed - what's in the way?

A
Alexander Pryadko, 2018-01-30
@alexander_v_pryadko

The availability check must be done on the server, in the place where the goods are reserved (if it is implemented), everything else is unreliable and stupid: the number limiting the quantity may change in the process of filling in the field. In fact, the restriction will stop working normally. It is worth limiting only in one case: no more than XXX in one hand (order). Then any check running on the client in the browser is suitable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question