diff --git a/.gitignore b/.gitignore index 2c1fc0c1..9c10d38d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor composer.phar composer.lock -.DS_Store \ No newline at end of file +.DS_Store +.idea diff --git a/composer.json b/composer.json index 41f7b92a..677caa7f 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,9 @@ } ], "require": { - "illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.*", - "illuminate/session": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.*", - "illuminate/events": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*|| 5.6.* || 5.7.*" + "illuminate/support": "~6.0 || ~7.0 || ~8.0 || ~9.0 || ~10.0", + "illuminate/session": "~6.0 || ~7.0 || ~8.0 || ~9.0 || ~10.0", + "illuminate/events": "~6.0 || ~7.0 || ~8.0 || ~9.0 || ~10.0" }, "require-dev": { "phpunit/phpunit": "~5.0 || ~6.0 || ~7.0", diff --git a/src/Cart.php b/src/Cart.php index 09853dba..a2662cb9 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -104,7 +104,7 @@ public function add($id, $name = null, $qty = null, $price = null, array $option $content->put($cartItem->rowId, $cartItem); - $this->events->fire('cart.added', $cartItem); + $this->events->dispatch('cart.added', $cartItem); $this->session->put($this->instance, $content); @@ -148,7 +148,7 @@ public function update($rowId, $qty) $content->put($cartItem->rowId, $cartItem); } - $this->events->fire('cart.updated', $cartItem); + $this->events->dispatch('cart.updated', $cartItem); $this->session->put($this->instance, $content); @@ -169,7 +169,7 @@ public function remove($rowId) $content->pull($cartItem->rowId); - $this->events->fire('cart.removed', $cartItem); + $this->events->dispatch('cart.removed', $cartItem); $this->session->put($this->instance, $content); } @@ -360,7 +360,7 @@ public function store($identifier) 'content' => serialize($content) ]); - $this->events->fire('cart.stored'); + $this->events->dispatch('cart.stored'); } /** @@ -390,7 +390,7 @@ public function restore($identifier) $content->put($cartItem->rowId, $cartItem); } - $this->events->fire('cart.restored'); + $this->events->dispatch('cart.restored'); $this->session->put($this->instance, $content); diff --git a/src/CartItem.php b/src/CartItem.php index 64e2cf68..8215c43a 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -5,6 +5,7 @@ use Illuminate\Contracts\Support\Arrayable; use Gloudemans\Shoppingcart\Contracts\Buyable; use Illuminate\Contracts\Support\Jsonable; +use Illuminate\Support\Arr; class CartItem implements Arrayable, Jsonable { @@ -103,7 +104,7 @@ public function price($decimals = null, $decimalPoint = null, $thousandSeperator { return $this->numberFormat($this->price, $decimals, $decimalPoint, $thousandSeperator); } - + /** * Returns the formatted price with TAX. * @@ -130,7 +131,7 @@ public function subtotal($decimals = null, $decimalPoint = null, $thousandSepera { return $this->numberFormat($this->subtotal, $decimals, $decimalPoint, $thousandSeperator); } - + /** * Returns the formatted total. * Total is price for whole CartItem with TAX @@ -157,7 +158,7 @@ public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = { return $this->numberFormat($this->tax, $decimals, $decimalPoint, $thousandSeperator); } - + /** * Returns the formatted tax. * @@ -206,12 +207,12 @@ public function updateFromBuyable(Buyable $item) */ public function updateFromArray(array $attributes) { - $this->id = array_get($attributes, 'id', $this->id); - $this->qty = array_get($attributes, 'qty', $this->qty); - $this->name = array_get($attributes, 'name', $this->name); - $this->price = array_get($attributes, 'price', $this->price); + $this->id = Arr::get($attributes, 'id', $this->id); + $this->qty = Arr::get($attributes, 'qty', $this->qty); + $this->name = Arr::get($attributes, 'name', $this->name); + $this->price = Arr::get($attributes, 'price', $this->price); $this->priceTax = $this->price + $this->tax; - $this->options = new CartItemOptions(array_get($attributes, 'options', $this->options)); + $this->options = new CartItemOptions(Arr::get($attributes, 'options', $this->options)); $this->rowId = $this->generateRowId($this->id, $this->options->all()); } @@ -225,7 +226,7 @@ public function updateFromArray(array $attributes) public function associate($model) { $this->associatedModel = is_string($model) ? $model : get_class($model); - + return $this; } @@ -238,7 +239,7 @@ public function associate($model) public function setTaxRate($taxRate) { $this->taxRate = $taxRate; - + return $this; } @@ -257,11 +258,11 @@ public function __get($attribute) if($attribute === 'priceTax') { return $this->price + $this->tax; } - + if($attribute === 'subtotal') { return $this->qty * $this->price; } - + if($attribute === 'total') { return $this->qty * ($this->priceTax); } @@ -269,7 +270,7 @@ public function __get($attribute) if($attribute === 'tax') { return $this->price * ($this->taxRate / 100); } - + if($attribute === 'taxTotal') { return $this->tax * $this->qty; } @@ -301,7 +302,7 @@ public static function fromBuyable(Buyable $item, array $options = []) */ public static function fromArray(array $attributes) { - $options = array_get($attributes, 'options', []); + $options = Arr::get($attributes, 'options', []); return new self($attributes['id'], $attributes['name'], $attributes['price'], $options); }