diff --git a/src/Bazar.php b/src/Bazar.php index 954c3472..295957a6 100644 --- a/src/Bazar.php +++ b/src/Bazar.php @@ -12,7 +12,7 @@ abstract class Bazar * * @var string */ - public const VERSION = '1.1.1'; + public const VERSION = '1.1.2'; /** * The currency in use. diff --git a/src/Interfaces/LineItem.php b/src/Interfaces/LineItem.php index 84ed9d45..53123098 100644 --- a/src/Interfaces/LineItem.php +++ b/src/Interfaces/LineItem.php @@ -19,6 +19,16 @@ public function getPrice(): float; */ public function getFormattedPrice(): string; + /** + * Get the gross price. + */ + public function getGrossPrice(): float; + + /** + * Get the formatted price. + */ + public function getFormattedGrossPrice(): string; + /** * Get the total. */ diff --git a/src/Models/Item.php b/src/Models/Item.php index 36f284cf..2a78c0a8 100644 --- a/src/Models/Item.php +++ b/src/Models/Item.php @@ -135,6 +135,18 @@ protected function formattedPrice(): Attribute ); } + /** + * Get the formatted gross price attribute. + * + * @return \Illuminate\Database\Eloquent\Casts\Attribute + */ + protected function formattedGrossPrice(): Attribute + { + return new Attribute( + get: fn (): string => $this->getFormattedGrossPrice(), + ); + } + /** * Get the total attribute. * @@ -207,12 +219,28 @@ public function getFormattedPrice(): string return (new Currency($this->getPrice(), $this->checkoutable->getCurrency()))->format(); } + /** + * Get the gross price. + */ + public function getGrossPrice(): float + { + return $this->getPrice() + $this->getTax(); + } + + /** + * Get the formatted price. + */ + public function getFormattedGrossPrice(): string + { + return (new Currency($this->getGrossPrice(), $this->checkoutable->getCurrency()))->format(); + } + /** * Get the total. */ public function getTotal(): float { - return ($this->getPrice() + $this->getTax()) * $this->getQuantity(); + return $this->getGrossPrice() * $this->getQuantity(); } /** diff --git a/src/Models/Shipping.php b/src/Models/Shipping.php index 97ae7b1e..1a8743f0 100644 --- a/src/Models/Shipping.php +++ b/src/Models/Shipping.php @@ -221,12 +221,28 @@ public function getFormattedPrice(): string return (new Currency($this->getPrice(), $this->shippable->getCurrency()))->format(); } + /** + * Get the gross price. + */ + public function getGrossPrice(): float + { + return $this->getPrice() + $this->getTax(); + } + + /** + * Get the formatted price. + */ + public function getFormattedGrossPrice(): string + { + return (new Currency($this->getGrossPrice(), $this->shippable->getCurrency()))->format(); + } + /** * Get the shipping's total. */ public function getTotal(): float { - return $this->getPrice() + $this->getTaxTotal(); + return $this->getGrossPrice() * $this->getQuantity(); } /** diff --git a/tests/Models/ProductTest.php b/tests/Models/ProductTest.php index 717bfb4b..7a6f35e3 100644 --- a/tests/Models/ProductTest.php +++ b/tests/Models/ProductTest.php @@ -111,6 +111,11 @@ public function test_a_product_belongs_to_tax_rates(): void $this->assertTrue($this->product->taxRates->contains($taxRate)); } + public function test_(): void + { + $this->assertTrue(true); + } + public function test_product_interacts_with_stock(): void { $this->assertTrue(true);