diff --git a/src/Cart/CartManager.php b/src/Cart/CartManager.php index d909b246..c1c234cd 100644 --- a/src/Cart/CartManager.php +++ b/src/Cart/CartManager.php @@ -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(); diff --git a/src/Cart/Models/Cart.php b/src/Cart/Models/Cart.php index 52fc090d..60b302f2 100644 --- a/src/Cart/Models/Cart.php +++ b/src/Cart/Models/Cart.php @@ -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 * diff --git a/src/Contracts/Changelog.md b/src/Contracts/Changelog.md index 116fd6c8..97a9a9f8 100644 --- a/src/Contracts/Changelog.md +++ b/src/Contracts/Changelog.md @@ -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 diff --git a/src/Contracts/CheckoutSubject.php b/src/Contracts/CheckoutSubject.php index e1afee33..55ec8710 100644 --- a/src/Contracts/CheckoutSubject.php +++ b/src/Contracts/CheckoutSubject.php @@ -22,10 +22,13 @@ interface CheckoutSubject { /** - * A collection of CheckoutSubjectItem objects + * + * @return Collection */ public function getItems(): Collection; + public function itemsTotal(): float; + /** * Returns the final total of the CheckoutSubject (typically a cart) */