Skip to content

Commit

Permalink
[CartController] Add limit for maximum cart items - #resolves 262
Browse files Browse the repository at this point in the history
  • Loading branch information
dvesh3 committed Dec 2, 2021
1 parent 0a5fe14 commit b1c1c51
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Controller/CartController.php
Expand Up @@ -73,6 +73,10 @@ public function addToCartAction(Request $request, Factory $ecommerceFactory)
}

$cart = $this->getCart();
if ($cart->getItemCount() > 99) {
throw new \Exception('Maximum Cart items limit Reached');
}

$cart->addItem($product, 1);
$cart->save();

Expand Down Expand Up @@ -100,6 +104,9 @@ public function cartListingAction(Request $request, BreadcrumbHelperService $bre
$items = $request->get('items');

foreach ($items as $itemKey => $quantity) {
if ($cart->getItemCount() > 99) {
break;
}
$product = AbstractProduct::getById($itemKey);
if ($product instanceof CheckoutableInterface) {
$cart->updateItem($itemKey, $product, $quantity, true);
Expand Down

0 comments on commit b1c1c51

Please sign in to comment.