This commit is contained in:
Patrick Henninger
2022-02-06 19:28:56 +01:00
parent c4fb20271f
commit 5d55788584
9 changed files with 62 additions and 62 deletions

View File

@@ -2,9 +2,8 @@
namespace Gloudemans\Shoppingcart; namespace Gloudemans\Shoppingcart;
use Gloudemans\Shoppingcart\CartItemOptions;
use Money\Money;
use Money\Currency; use Money\Currency;
use Money\Money;
trait CanBeBought trait CanBeBought
{ {

View File

@@ -2,11 +2,8 @@
namespace Gloudemans\Shoppingcart; namespace Gloudemans\Shoppingcart;
use Closure;
use InvalidArgumentException;
use Carbon\Carbon; use Carbon\Carbon;
use Money\Money; use Closure;
use Money\Currency;
use Gloudemans\Shoppingcart\Contracts\Buyable; use Gloudemans\Shoppingcart\Contracts\Buyable;
use Gloudemans\Shoppingcart\Contracts\InstanceIdentifier; use Gloudemans\Shoppingcart\Contracts\InstanceIdentifier;
use Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException; use Gloudemans\Shoppingcart\Exceptions\CartAlreadyStoredException;
@@ -17,8 +14,11 @@ use Illuminate\Database\DatabaseManager;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Session\SessionManager; use Illuminate\Session\SessionManager;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Traits\Macroable;
use InvalidArgumentException;
use Money\Currency;
use Money\Money;
class Cart class Cart
{ {
@@ -363,7 +363,7 @@ class Cart
if ($calculated instanceof Money) { if ($calculated instanceof Money) {
return $calculated; return $calculated;
} else { } else {
throw new \TypeError("Calculated price is not an instance of Money"); throw new \TypeError('Calculated price is not an instance of Money');
} }
} }
@@ -381,7 +381,7 @@ class Cart
if ($calculated instanceof Money) { if ($calculated instanceof Money) {
return $calculated; return $calculated;
} else { } else {
throw new \TypeError("Calculated discount is not an instance of Money"); throw new \TypeError('Calculated discount is not an instance of Money');
} }
} }
@@ -397,7 +397,7 @@ class Cart
if ($calculated instanceof Money) { if ($calculated instanceof Money) {
return $calculated; return $calculated;
} else { } else {
throw new \TypeError("Calculated subtotal is not an instance of Money"); throw new \TypeError('Calculated subtotal is not an instance of Money');
} }
} }
@@ -427,7 +427,7 @@ class Cart
if ($calculated instanceof Money) { if ($calculated instanceof Money) {
return $calculated; return $calculated;
} else { } else {
throw new \TypeError("Calculated total is not an instance of Money"); throw new \TypeError('Calculated total is not an instance of Money');
} }
} }
@@ -443,7 +443,7 @@ class Cart
if (is_int($calculated)) { if (is_int($calculated)) {
return $calculated; return $calculated;
} else { } else {
throw new \TypeError("Calculated weight was not an integer"); throw new \TypeError('Calculated weight was not an integer');
} }
} }

View File

@@ -8,9 +8,9 @@ use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Money\Money;
use Money\Formatter\DecimalMoneyFormatter;
use Money\Currencies\ISOCurrencies; use Money\Currencies\ISOCurrencies;
use Money\Formatter\DecimalMoneyFormatter;
use Money\Money;
class CartItem implements Arrayable, Jsonable class CartItem implements Arrayable, Jsonable
{ {
@@ -197,7 +197,7 @@ class CartItem implements Arrayable, Jsonable
} }
/** /**
* This is the tax, based on the subtotal (all previous calculations) and set tax rate * This is the tax, based on the subtotal (all previous calculations) and set tax rate.
*/ */
public function tax(): Money public function tax(): Money
{ {
@@ -226,6 +226,7 @@ class CartItem implements Arrayable, Jsonable
public static function fromBuyable(Buyable $item, int $qty = 1, ?CartItemOptions $options = null): self public static function fromBuyable(Buyable $item, int $qty = 1, ?CartItemOptions $options = null): self
{ {
$options = $options ?: new CartItemOptions([]); $options = $options ?: new CartItemOptions([]);
return new self($item->getBuyableIdentifier($options), $item->getBuyableDescription($options), $item->getBuyablePrice($options), $qty, $item->getBuyableWeight($options), $options); return new self($item->getBuyableIdentifier($options), $item->getBuyableDescription($options), $item->getBuyablePrice($options), $qty, $item->getBuyableWeight($options), $options);
} }
@@ -235,6 +236,7 @@ class CartItem implements Arrayable, Jsonable
public static function fromArray(array $attributes): self public static function fromArray(array $attributes): self
{ {
$options = new CartItemOptions(Arr::get($attributes, 'options', [])); $options = new CartItemOptions(Arr::get($attributes, 'options', []));
return new self($attributes['id'], $attributes['name'], $attributes['price'], $attributes['qty'], $attributes['weight'], $options); return new self($attributes['id'], $attributes['name'], $attributes['price'], $attributes['qty'], $attributes['weight'], $options);
} }
@@ -246,6 +248,7 @@ class CartItem implements Arrayable, Jsonable
public static function fromAttributes(int|string $id, string $name, Money $price, int $qty = 1, int $weight = 0, ?CartItemOptions $options = null): self public static function fromAttributes(int|string $id, string $name, Money $price, int $qty = 1, int $weight = 0, ?CartItemOptions $options = null): self
{ {
$options = $options ?: new CartItemOptions([]); $options = $options ?: new CartItemOptions([]);
return new self($id, $name, $price, $qty, $weight, $options); return new self($id, $name, $price, $qty, $weight, $options);
} }

View File

@@ -2,8 +2,6 @@
namespace Gloudemans\Shoppingcart; namespace Gloudemans\Shoppingcart;
use Illuminate\Auth\Events\Logout;
use Illuminate\Session\SessionManager;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class ShoppingcartServiceProvider extends ServiceProvider class ShoppingcartServiceProvider extends ServiceProvider

View File

@@ -5,9 +5,9 @@ namespace Gloudemans\Tests\Shoppingcart;
use Gloudemans\Shoppingcart\CartItem; use Gloudemans\Shoppingcart\CartItem;
use Gloudemans\Shoppingcart\CartItemOptions; use Gloudemans\Shoppingcart\CartItemOptions;
use Gloudemans\Shoppingcart\ShoppingcartServiceProvider; use Gloudemans\Shoppingcart\ShoppingcartServiceProvider;
use Orchestra\Testbench\TestCase;
use Money\Money;
use Money\Currency; use Money\Currency;
use Money\Money;
use Orchestra\Testbench\TestCase;
class CartItemTest extends TestCase class CartItemTest extends TestCase
{ {

View File

@@ -3,8 +3,6 @@
namespace Gloudemans\Tests\Shoppingcart; namespace Gloudemans\Tests\Shoppingcart;
use Carbon\Carbon; use Carbon\Carbon;
use Money\Money;
use Money\Currency;
use Gloudemans\Shoppingcart\Cart; use Gloudemans\Shoppingcart\Cart;
use Gloudemans\Shoppingcart\CartItem; use Gloudemans\Shoppingcart\CartItem;
use Gloudemans\Shoppingcart\CartItemOptions; use Gloudemans\Shoppingcart\CartItemOptions;
@@ -15,6 +13,8 @@ use Gloudemans\Tests\Shoppingcart\Fixtures\Identifiable;
use Gloudemans\Tests\Shoppingcart\Fixtures\ProductModel; use Gloudemans\Tests\Shoppingcart\Fixtures\ProductModel;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Money\Currency;
use Money\Money;
use Orchestra\Testbench\TestCase; use Orchestra\Testbench\TestCase;
class CartTest extends TestCase class CartTest extends TestCase
@@ -31,7 +31,7 @@ class CartTest extends TestCase
protected function getPackageProviders($app) protected function getPackageProviders($app)
{ {
return [ return [
ShoppingcartServiceProvider::class ShoppingcartServiceProvider::class,
]; ];
} }

View File

@@ -2,11 +2,11 @@
namespace Gloudemans\Tests\Shoppingcart\Fixtures; namespace Gloudemans\Tests\Shoppingcart\Fixtures;
use Gloudemans\Shoppingcart\Contracts\Buyable;
use Gloudemans\Shoppingcart\CartItemOptions; use Gloudemans\Shoppingcart\CartItemOptions;
use Gloudemans\Shoppingcart\Contracts\Buyable;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Money\Money;
use Money\Currency; use Money\Currency;
use Money\Money;
class BuyableProduct extends Model implements Buyable class BuyableProduct extends Model implements Buyable
{ {