Skip to content

Commit

Permalink
Added the itemsTotal() method to the CheckoutSubject interface
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Mar 1, 2024
1 parent 988d015 commit 11ec51d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/Cart/CartManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ public function getItems(): Collection
return $this->exists() ? $this->model()->getItems() : collect();
}

/**
* @inheritDoc
*/
public function addItem(Buyable $product, $qty = 1, $params = []): CartItem
public function itemsTotal(): float
{
return $this->exists() ? $this->model()->itemsTotal() : 0;
}

public function addItem(Buyable $product, int|float $qty = 1, array $params = []): CartItem
{
$cart = $this->findOrCreateCart();

Expand Down
5 changes: 5 additions & 0 deletions src/Cart/Models/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public function total(): float
return $this->items->sum('total');
}

public function itemsTotal(): float
{
return $this->items->sum('total');
}

/**
* The cart's user relationship
*
Expand Down
1 change: 1 addition & 0 deletions src/Contracts/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Added the `Merchant` interface
- Added the `Schematized` interface
- Added the `getConfigurationSchema()` method to the `Configurable` interface
- BC: Added the `itemsTotal()` method to the `CheckoutSubject` interface
- Added the nette/schema package requirement (v1.2.5+)

## 3.x Series
Expand Down
5 changes: 4 additions & 1 deletion src/Contracts/CheckoutSubject.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
interface CheckoutSubject
{
/**
* A collection of CheckoutSubjectItem objects
*
* @return Collection<CheckoutSubjectItem>
*/
public function getItems(): Collection;

public function itemsTotal(): float;

/**
* Returns the final total of the CheckoutSubject (typically a cart)
*/
Expand Down

0 comments on commit 11ec51d

Please sign in to comment.