Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed Jul 2, 2024
1 parent d02b306 commit d65c29c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Classes/CartManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class CartManager
*/
protected $settings;

protected $menuItemCache = [];

public function __construct()
{
$this->cart = App::make('cart');
Expand Down Expand Up @@ -68,7 +70,11 @@ public function findMenuItem($menuId)
throw new ApplicationException(lang('igniter.cart::default.alert_no_menu_selected'));
}

return Menu::findBy($menuId, $this->location->current());
if (array_key_exists($menuId, $this->menuItemCache)) {
return $this->menuItemCache[$menuId];
}

return $this->menuItemCache[$menuId] = Menu::findBy($menuId, $this->location->current());
}

public function addCartItem($menuId, array $properties = [])
Expand Down Expand Up @@ -285,7 +291,7 @@ public function validateContents()
}

$this->cart->content()->each(function(CartItem $cartItem) {
$menuItem = $cartItem->model;
$menuItem = $this->findMenuItem($cartItem->id);

$this->validateCartMenuItem($menuItem, $cartItem->qty);

Expand Down
4 changes: 2 additions & 2 deletions src/Classes/OrderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public function getCartTotals()
$total = [
'code' => $condition->name,
'title' => $condition->getLabel(),
'value' => $condition->getValue(),
'value' => is_numeric($value = $condition->getValue()) ? $value : 0,
'priority' => $condition->getPriority() ?: 1,
'is_summable' => false,
];
Expand All @@ -322,7 +322,7 @@ public function getCartTotals()
return [
'code' => $condition->name,
'title' => $condition->getLabel(),
'value' => $condition->getValue(),
'value' => is_numeric($value = $condition->getValue()) ? $value : 0,
'priority' => $condition->getPriority() ?: 1,
'is_summable' => !$condition->isInclusive(),
];
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function isCancelable()
return false;
}

return floor($this->order_datetime->diffInRealMinutes()) > $timeout;
return now()->diffInRealMinutes($this->reservation_datetime) > $timeout;

Check failure on line 199 in src/Models/Order.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\Cart\Models\Order::$reservation_datetime.

Check failure on line 199 in src/Models/Order.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Call to an undefined method Illuminate\Support\Carbon::diffInRealMinutes().

Check failure on line 199 in src/Models/Order.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\Cart\Models\Order::$reservation_datetime.

Check failure on line 199 in src/Models/Order.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Call to an undefined method Illuminate\Support\Carbon::diffInRealMinutes().
}

/**
Expand Down

0 comments on commit d65c29c

Please sign in to comment.