From 964ec6add0f0a1896feb0e2a5fc3ddf2c8a5a531 Mon Sep 17 00:00:00 2001 From: Jorge Moura Date: Tue, 22 Sep 2020 11:33:52 -0500 Subject: [PATCH 1/3] Update README.md Added new events description. --- README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 69327d0..017124b 100644 --- a/README.md +++ b/README.md @@ -653,15 +653,18 @@ The Cart package will throw exceptions if something goes wrong. This way it's ea The cart also has events build in. There are five events available for you to listen for. -| Event | Fired | Parameter | -| ------------- | ---------------------------------------- | -------------------------------- | -| cart.added | When an item was added to the cart. | The `CartItem` that was added. | -| cart.updated | When an item in the cart was updated. | The `CartItem` that was updated. | -| cart.removed | When an item is removed from the cart. | The `CartItem` that was removed. | -| cart.merged | When the content of a cart is merged | - | -| cart.stored | When the content of a cart was stored. | - | -| cart.restored | When the content of a cart was restored. | - | -| cart.erased | When the content of a cart was erased. | - | +| Event | Fired | Parameter | +| ------------- | ---------------------------------------- | ------------------------------------- | +| cart.adding | When adding an item to the cart. | The `CartItem` that is being added. | +| cart.updating | When updating an item to the cart. | The `CartItem` that is being updated. | +| cart.removing | When removing an item to the cart. | The `CartItem` that is being removed. | +| cart.added | When an item was added to the cart. | The `CartItem` that was added. | +| cart.updated | When an item was updated to the cart. | The `CartItem` that was updated. | +| cart.removed | When an item was removed from the cart. | The `CartItem` that was removed. | +| cart.merged | When the content of a cart is merged | - | +| cart.stored | When the content of a cart was stored. | - | +| cart.restored | When the content of a cart was restored. | - | +| cart.erased | When the content of a cart was erased. | - | ## Example From 143eb0b5d0793d524255a23a18543dbf7de2137d Mon Sep 17 00:00:00 2001 From: Jorge Moura Date: Tue, 22 Sep 2020 11:37:17 -0500 Subject: [PATCH 2/3] Added new events adding, updating, removing. --- src/Cart.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Cart.php b/src/Cart.php index a28e1ec..72a736e 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -167,10 +167,14 @@ class Cart $content->put($item->rowId, $item); if ($dispatchEvent) { - $this->events->dispatch('cart.added', $item); + $this->events->dispatch('cart.adding', $item); } $this->session->put($this->instance, $content); + + if ($dispatchEvent) { + $this->events->dispatch('cart.added', $item); + } return $item; } @@ -222,9 +226,11 @@ class Cart } } - $this->events->dispatch('cart.updated', $cartItem); + $this->events->dispatch('cart.updating', $cartItem); $this->session->put($this->instance, $content); + + $this->events->dispatch('cart.updated', $cartItem); return $cartItem; } @@ -244,9 +250,11 @@ class Cart $content->pull($cartItem->rowId); - $this->events->dispatch('cart.removed', $cartItem); + $this->events->dispatch('cart.removing', $cartItem); $this->session->put($this->instance, $content); + + $this->events->dispatch('cart.removed', $cartItem); } /** From 0991d4e6d471945280da4360034c656debf2574c Mon Sep 17 00:00:00 2001 From: Patrick Henninger Date: Wed, 23 Sep 2020 02:05:13 +0200 Subject: [PATCH 3/3] StyleCI --- src/Cart.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cart.php b/src/Cart.php index 72a736e..369bb2e 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -171,7 +171,7 @@ class Cart } $this->session->put($this->instance, $content); - + if ($dispatchEvent) { $this->events->dispatch('cart.added', $item); } @@ -229,7 +229,7 @@ class Cart $this->events->dispatch('cart.updating', $cartItem); $this->session->put($this->instance, $content); - + $this->events->dispatch('cart.updated', $cartItem); return $cartItem; @@ -253,7 +253,7 @@ class Cart $this->events->dispatch('cart.removing', $cartItem); $this->session->put($this->instance, $content); - + $this->events->dispatch('cart.removed', $cartItem); }