Update Cart.php

This commit is contained in:
Patrick
2022-01-18 00:54:05 +01:00
committed by GitHub
parent 23325c2bb7
commit 83f6d94a94

View File

@@ -54,10 +54,8 @@ class Cart
/** /**
* Defines the discount percentage. * Defines the discount percentage.
*
* @var float
*/ */
private $discount = 0; private ?Money $discount = null;
/** /**
* Defines the tax rate. * Defines the tax rate.
@@ -124,7 +122,7 @@ class Cart
* *
* @return \Gloudemans\Shoppingcart\CartItem * @return \Gloudemans\Shoppingcart\CartItem
*/ */
public function add($id, ?string $name = null, $qty = null, $price = null, $weight = 0, array $options = []) public function add($id, ?string $name = null, $qty = null, ?Money $price = null, $weight = 0, array $options = [])
{ {
if ($this->isMulti($id)) { if ($this->isMulti($id)) {
return array_map(function ($item) { return array_map(function ($item) {
@@ -751,7 +749,7 @@ class Cart
* *
* @return \Gloudemans\Shoppingcart\CartItem * @return \Gloudemans\Shoppingcart\CartItem
*/ */
private function createCartItem($id, ?string $name = null, $qty, $price, $weight, array $options) : CartItem private function createCartItem($id, ?string $name = null, int $qty, ?Money $price = null, int $weight = 0, array $options = []) : CartItem
{ {
if ($id instanceof Buyable) { if ($id instanceof Buyable) {
$cartItem = CartItem::fromBuyable($id, $qty ?: []); $cartItem = CartItem::fromBuyable($id, $qty ?: []);
@@ -777,7 +775,7 @@ class Cart
* *
* @return bool * @return bool
*/ */
private function isMulti($item) private function isMulti($item) : bool
{ {
if (!is_array($item)) { if (!is_array($item)) {
return false; return false;
@@ -791,7 +789,7 @@ class Cart
* *
* @return bool * @return bool
*/ */
private function storedCartInstanceWithIdentifierExists($instance, $identifier) private function storedCartInstanceWithIdentifierExists(string $instance, string $identifier) : bool
{ {
return $this->getConnection()->table($this->getTableName())->where(['identifier' => $identifier, 'instance'=> $instance])->exists(); return $this->getConnection()->table($this->getTableName())->where(['identifier' => $identifier, 'instance'=> $instance])->exists();
} }
@@ -811,7 +809,7 @@ class Cart
* *
* @return string * @return string
*/ */
private function getTableName() private function getTableName() : string
{ {
return config('cart.database.table', 'shoppingcart'); return config('cart.database.table', 'shoppingcart');
} }
@@ -821,7 +819,7 @@ class Cart
* *
* @return string * @return string
*/ */
private function getConnectionName() private function getConnectionName() : string
{ {
$connection = config('cart.database.connection'); $connection = config('cart.database.connection');
@@ -838,7 +836,7 @@ class Cart
* *
* @return string * @return string
*/ */
private function numberFormat($value, ?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null) private function numberFormat($value, ?int $decimals = null, ?string $decimalPoint = null, ?string $thousandSeperator = null) : string
{ {
if (is_null($decimals)) { if (is_null($decimals)) {
$decimals = config('cart.format.decimals', 2); $decimals = config('cart.format.decimals', 2);