mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-23 15:41:24 +00:00
Fix tests
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ return [
|
||||
|
|
||||
*/
|
||||
|
||||
'tax' => 21,
|
||||
'tax' => 0.21,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user