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 +34 -6 1.6.2 → 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
@@ -411,8 +424,12 @@
411 424 // that means we have to remove it
412 425 return $this->removeItem($variation->id, Arr::get($config, 'remove_args', []), true);
413 426 }
414 427
428 + if (!$variation->product) {
429 + return new \WP_Error('product_not_found', __('This product is no longer available.', 'fluent-cart'));
430 + }
431 +
415 432 $validate = Arr::get($config, 'will_validate', false);
416 433
417 434 $replacingIndex = null;
418 435
@@ -445,8 +462,14 @@
445 462 // remove the item if quantity is zero or negative after adjustment
446 463 return $this->removeItem($variation->id);
447 464 }
448 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 +
449 472 if ($validate) {
450 473 $canPurchase = $variation->canPurchase($quantity);
451 474 $canPurchase = apply_filters('fluent_cart/cart/can_purchase', $canPurchase, [
452 475 'cart' => $this,
@@ -494,9 +517,14 @@
494 517 __('Invalid custom item data.', 'fluent-cart')
495 518 );
496 519 }
497 520
498 - $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;
499 527 $variationId = Arr::get($variation, 'id');
500 528
501 529 if ($quantity == 0) {
502 530 // that means we have to remove it