PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.7.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.7.1
1.7.1 1.7.0 1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 All 51 releases
← All changes | app/Models/Cart.php +30 -6 1.6.4 → 1.7.1 View file →
@@ -313,16 +313,24 @@
313 313 *
314 314 * Deliberately distinct from isLocked(), which additionally requires order_id
315 315 * and is therefore false for renewal and early-installment carts, which never
316 316 * set that column.
317 + *
318 + * Filterable so an integration that locks its cart only to pin its own item
319 + * (e.g. a booking) can still take order bumps. The filter only decides the
320 + * lock; a cart carrying an upgrade is refused after it either way. The upgrade
321 + * swap in WebCheckoutHandler::handleOrderBumpRequest() ignores this filter and
322 + * keeps refusing any `is_locked` cart.
317 323 */
318 324 public function acceptsAdditionalItems()
319 325 {
320 - if (Arr::get($this->checkout_data, 'is_locked') === 'yes') {
321 - return false;
322 - }
326 + $accepts = (bool) apply_filters(
327 + 'fluent_cart/cart/accepts_additional_items',
328 + Arr::get($this->checkout_data, 'is_locked') !== 'yes',
329 + ['cart' => $this]
330 + );
323 331
324 - return empty(Arr::get($this->checkout_data, 'upgrade_data'));
332 + return $accepts && empty(Arr::get($this->checkout_data, 'upgrade_data'));
325 333 }
326 334
327 335 public function addItem($item = [], $replacingIndex = null)
328 336 {
@@ -403,9 +411,14 @@
403 411 }
404 412
405 413 public function addByVariation(ProductVariation $variation, $config = [])
406 414 {
407 - $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;
408 421 $byInput = Arr::get($config, 'by_input', false);
409 422
410 423 if ($quantity == 0) {
411 424 // that means we have to remove it
@@ -449,8 +462,14 @@
449 462 // remove the item if quantity is zero or negative after adjustment
450 463 return $this->removeItem($variation->id);
451 464 }
452 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 +
453 472 if ($validate) {
454 473 $canPurchase = $variation->canPurchase($quantity);
455 474 $canPurchase = apply_filters('fluent_cart/cart/can_purchase', $canPurchase, [
456 475 'cart' => $this,
@@ -498,9 +517,14 @@
498 517 __('Invalid custom item data.', 'fluent-cart')
499 518 );
500 519 }
501 520
502 - $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;
503 527 $variationId = Arr::get($variation, 'id');
504 528
505 529 if ($quantity == 0) {
506 530 // that means we have to remove it