Quellcode durchsuchen

handle product quantity negative value

master
azri vor 1 Woche
Ursprung
Commit
7e3a7631fa
1 geänderte Dateien mit 6 neuen und 4 gelöschten Zeilen
  1. 6
    4
      src/components/ProductDetails/ProductDetails.jsx

+ 6
- 4
src/components/ProductDetails/ProductDetails.jsx Datei anzeigen

@@ -95,6 +95,8 @@ const ProductDetails = () => {
95 95
 
96 96
           if (hasMatchingProperties(newVariantSelection, optionsObject)) {
97 97
             newVariantSelection = { ...newVariantSelection, amount, currencyCode, id, quantityAvailable };
98
+            if (quantityAvailable <= 0) setQuantity(0)
99
+            else setQuantity(1)
98 100
             break; // Exit the loop when condition is met
99 101
           }
100 102
         }
@@ -139,7 +141,7 @@ const ProductDetails = () => {
139 141
 
140 142
         if (hasMatchingProperties(newVariantSelection, optionsObject)) {
141 143
           newVariantSelection = { ...newVariantSelection, amount, currencyCode, id, quantityAvailable };
142
-          if (quantityAvailable == 0) setQuantity(0)
144
+          if (quantityAvailable <= 0) setQuantity(0)
143 145
           else setQuantity(1)
144 146
           break; // Exit the loop when condition is met
145 147
         }
@@ -305,7 +307,7 @@ const ProductDetails = () => {
305 307
               variant="contained"
306 308
               color="primary"
307 309
               sx={{ width: "35px" }}
308
-              disabled={variantSelection?.quantityAvailable == 0 || quantity == 1}
310
+              disabled={variantSelection?.quantityAvailable <= 0 || quantity == 1}
309 311
               onClick={handleDecrement}
310 312
             >
311 313
               <RemoveIcon />
@@ -323,7 +325,7 @@ const ProductDetails = () => {
323 325
               variant="contained"
324 326
               color="primary"
325 327
               sx={{ width: "35px" }}
326
-              disabled={variantSelection?.quantityAvailable == 0 || quantity == variantSelection?.quantityAvailable}
328
+              disabled={variantSelection?.quantityAvailable <= 0 || quantity == variantSelection?.quantityAvailable}
327 329
               onClick={handleIncrement}
328 330
             >
329 331
               <AddIcon />
@@ -346,7 +348,7 @@ const ProductDetails = () => {
346 348
           variant="contained"
347 349
           color="common.black"
348 350
           fullWidth
349
-          disabled={variantSelection?.quantityAvailable == 0 || showLoader}
351
+          disabled={variantSelection?.quantityAvailable <= 0 || showLoader}
350 352
           sx={{
351 353
             backgroundColor: (theme) => theme.palette.common.black,
352 354
             color: "white",

Laden…
Abbrechen
Speichern