| @@ -411,9 +411,14 @@ | ||
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | public function addByVariation(ProductVariation $variation, $config = []) |
| 414 | 414 | { |
| 415 | - $quantity = (int)Arr::get($config, 'quantity', 1); | |
| 415 | + $quantity = Arr::get($config, 'quantity', 1); | |
| 416 | + $error = CartHelper::validateQuantity($quantity, true); | |
| 417 | + if ($error) { | |
| 418 | + return $error; | |
| 419 | + } | |
| 420 | + $quantity = (int)$quantity; | |
| 416 | 421 | $byInput = Arr::get($config, 'by_input', false); |
| 417 | 422 | |
| 418 | 423 | if ($quantity == 0) { |
| 419 | 424 | // that means we have to remove it |
| @@ -457,8 +462,14 @@ | ||
| 457 | 462 | // remove the item if quantity is zero or negative after adjustment |
| 458 | 463 | return $this->removeItem($variation->id); |
| 459 | 464 | } |
| 460 | 465 | |
| 466 | + // Repeated increments accumulate onto the stored quantity, so re-check the sum. | |
| 467 | + $error = CartHelper::validateQuantity($quantity); | |
| 468 | + if ($error) { | |
| 469 | + return $error; | |
| 470 | + } | |
| 471 | + | |
| 461 | 472 | if ($validate) { |
| 462 | 473 | $canPurchase = $variation->canPurchase($quantity); |
| 463 | 474 | $canPurchase = apply_filters('fluent_cart/cart/can_purchase', $canPurchase, [ |
| 464 | 475 | 'cart' => $this, |
| @@ -506,9 +517,14 @@ | ||
| 506 | 517 | __('Invalid custom item data.', 'fluent-cart') |
| 507 | 518 | ); |
| 508 | 519 | } |
| 509 | 520 | |
| 510 | - $quantity = (int)Arr::get($config, 'quantity', 1); | |
| 521 | + $quantity = Arr::get($config, 'quantity', 1); | |
| 522 | + $error = CartHelper::validateQuantity($quantity, true); | |
| 523 | + if ($error) { | |
| 524 | + return $error; | |
| 525 | + } | |
| 526 | + $quantity = (int)$quantity; | |
| 511 | 527 | $variationId = Arr::get($variation, 'id'); |
| 512 | 528 | |
| 513 | 529 | if ($quantity == 0) { |
| 514 | 530 | // that means we have to remove it |