Add a method to check that an item in a cart.

main
KKlochko 2 years ago
parent 73b45084b7
commit e91b808a0f

@ -51,6 +51,17 @@ class Cart extends Model
return $this->items()->pluck('item_id')->toArray(); return $this->items()->pluck('item_id')->toArray();
} }
public function isItemIn(Item $item): bool
{
$itemsIds = $this->getItemIds();
$countOfMatches = Item::whereIn('id', $itemsIds)
->where('uuid', $item->uuid)
->count();
return $countOfMatches != 0;
}
public function isEmpty() public function isEmpty()
{ {
return count($this->getItemIds()); return count($this->getItemIds());

Loading…
Cancel
Save