Skip to content

Commit

Permalink
handle gorss price
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Nov 1, 2024
1 parent 17ea7c9 commit e204d58
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Bazar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions src/Interfaces/LineItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
30 changes: 29 additions & 1 deletion src/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ protected function formattedPrice(): Attribute
);
}

/**
* Get the formatted gross price attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<string, never>
*/
protected function formattedGrossPrice(): Attribute
{
return new Attribute(
get: fn (): string => $this->getFormattedGrossPrice(),
);
}

/**
* Get the total attribute.
*
Expand Down Expand Up @@ -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();
}

/**
Expand Down
18 changes: 17 additions & 1 deletion src/Models/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions tests/Models/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e204d58

Please sign in to comment.