Fix tests

This commit is contained in:
Patrick Henninger
2022-02-06 02:59:32 +01:00
parent 4fdc7a55e3
commit 0aa43abb67
5 changed files with 79 additions and 91 deletions

View File

@@ -525,13 +525,8 @@ class Cart
/**
* Set the discount rate for the cart item with the given rowId.
*
* @param string $rowId
* @param int|float $taxRate
*
* @return void
*/
public function setDiscount(string $rowId, $discount): void
public function setDiscount(string $rowId, float|Money $discount): void
{
$cartItem = $this->get($rowId);

View File

@@ -180,9 +180,11 @@ class CartItem implements Arrayable, Jsonable
*/
public function discount(): Money
{
$price = $this->price();
if ($this->discount instanceof Money) {
return $this->price()->subtract($this->discount);
} else {
$result = $this->price()->multiply($this->discount, Config::get('cart.rounding', Money::ROUND_UP));
return $this->price()->multiply($this->discount, Config::get('cart.rounding', Money::ROUND_UP));
}
}
@@ -193,7 +195,8 @@ class CartItem implements Arrayable, Jsonable
*/
public function subtotal(): Money
{
return Money::max(new Money(0, $this->price()->getCurrency()), $this->price()->add($this->discount()));
$subtotal = $this->price()->add($this->discount());
return Money::max(new Money(0, $this->price->getCurrency()), $this->price()->subtract($this->discount()));
}
/**
@@ -201,7 +204,8 @@ class CartItem implements Arrayable, Jsonable
*/
public function tax(): Money
{
return $this->subtotal()->multiply($this->taxRate + 1, Config::get('cart.rounding', Money::ROUND_UP));
$tax = $this->subtotal()->multiply($this->taxRate, Config::get('cart.rounding', Money::ROUND_UP));
return $this->subtotal()->multiply($this->taxRate, Config::get('cart.rounding', Money::ROUND_UP));
}
/**

View File

@@ -26,7 +26,7 @@ return [
|
*/
'tax' => 21,
'tax' => 0.21,
/*
|--------------------------------------------------------------------------