Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Jan 3, 2024
1 parent e66193f commit d7b2c19
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Interfaces/Discountable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ public function getDiscount(): float;
*/
public function getFormattedDiscount(): string;

/**
* Get the discount rate.
*/
public function getDiscountRate(): float;

/**
* Get the formatted discount rate.
*/
public function getFormattedDiscountRate(): string;

/**
* Calculate the discount.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Interfaces/Taxable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ public function getTax(): float;
*/
public function getFormattedTax(): string;

/**
* Get the tax rate.
*/
public function getTaxRate(): float;

/**
* Get the formatted tax rate.
*/
public function getFormattedTaxRate(): string;

/**
* Calculate the tax.
*/
Expand Down
17 changes: 17 additions & 0 deletions src/Models/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Number;

class Cart extends Model implements Contract
{
Expand Down Expand Up @@ -120,6 +121,22 @@ public function address(): MorphOne
});
}

/**
* Get the discount rate.
*/
public function getDiscountRate(): float
{
return $this->getSubtotal() > 0 ? ($this->getDiscount() / $this->getSubtotal()) * 100 : 0;
}

/**
* Get the formatted discount rate.
*/
public function getFormattedDiscountRate(): string
{
return Number::percentage($this->getDiscountRate());
}

/**
* Lock the cart.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ public function getFormattedSubtotal(): string
return Number::currency($this->getSubtotal(), $this->itemable->getCurrency());
}

/**
* Get the tax rate.
*/
public function getTaxRate(): float
{
return $this->getPrice() > 0 ? ($this->getTax() / $this->getPrice()) * 100 : 0;
}

/**
* Get the formatted tax rate.
*/
public function getFormattedTaxRate(): string
{
return Number::percentage($this->getTaxRate());
}

/**
* Get the quantity.
*/
Expand Down
17 changes: 17 additions & 0 deletions src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
use Illuminate\Support\Number;

class Order extends Model implements Contract
{
Expand Down Expand Up @@ -202,6 +203,22 @@ public function uniqueIds(): array
return ['uuid'];
}

/**
* Get the discount rate.
*/
public function getDiscountRate(): float
{
return $this->getSubtotal() > 0 ? ($this->getDiscount() / $this->getSubtotal()) * 100 : 0;
}

/**
* Get the formatted discount rate.
*/
public function getFormattedDiscountRate(): string
{
return Number::percentage($this->getDiscountRate());
}

/**
* Create a payment transaction for the order.
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Models/Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,22 @@ public function getFormattedSubtotal(): string
return Number::currency($this->getSubtotal(), $this->shippable->getCurrency());
}

/**
* Get the tax rate.
*/
public function getTaxRate(): float
{
return $this->getPrice() > 0 ? ($this->getTax() / $this->getPrice()) * 100 : 0;
}

/**
* Get the formatted tax rate.
*/
public function getFormattedTaxRate(): string
{
return Number::percentage($this->getTaxRate());
}

/**
* Get the quantity.
*/
Expand Down

0 comments on commit d7b2c19

Please sign in to comment.