mirror of
https://github.com/kevin-DL/LaravelShoppingcart.git
synced 2026-01-24 07:55:35 +00:00
Merge pull request #104 from manojo123/master
Add new events (adding, updating, removing)
This commit is contained in:
@@ -654,10 +654,13 @@ 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.
|
The cart also has events build in. There are five events available for you to listen for.
|
||||||
|
|
||||||
| Event | Fired | Parameter |
|
| 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.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.updated | When an item was updated to the cart. | The `CartItem` that was updated. |
|
||||||
| cart.removed | When an item is removed from the cart. | The `CartItem` that was removed. |
|
| 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.merged | When the content of a cart is merged | - |
|
||||||
| cart.stored | When the content of a cart was stored. | - |
|
| cart.stored | When the content of a cart was stored. | - |
|
||||||
| cart.restored | When the content of a cart was restored. | - |
|
| cart.restored | When the content of a cart was restored. | - |
|
||||||
|
|||||||
14
src/Cart.php
14
src/Cart.php
@@ -167,11 +167,15 @@ class Cart
|
|||||||
$content->put($item->rowId, $item);
|
$content->put($item->rowId, $item);
|
||||||
|
|
||||||
if ($dispatchEvent) {
|
if ($dispatchEvent) {
|
||||||
$this->events->dispatch('cart.added', $item);
|
$this->events->dispatch('cart.adding', $item);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->session->put($this->instance, $content);
|
$this->session->put($this->instance, $content);
|
||||||
|
|
||||||
|
if ($dispatchEvent) {
|
||||||
|
$this->events->dispatch('cart.added', $item);
|
||||||
|
}
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,10 +226,12 @@ class Cart
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->events->dispatch('cart.updated', $cartItem);
|
$this->events->dispatch('cart.updating', $cartItem);
|
||||||
|
|
||||||
$this->session->put($this->instance, $content);
|
$this->session->put($this->instance, $content);
|
||||||
|
|
||||||
|
$this->events->dispatch('cart.updated', $cartItem);
|
||||||
|
|
||||||
return $cartItem;
|
return $cartItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,9 +250,11 @@ class Cart
|
|||||||
|
|
||||||
$content->pull($cartItem->rowId);
|
$content->pull($cartItem->rowId);
|
||||||
|
|
||||||
$this->events->dispatch('cart.removed', $cartItem);
|
$this->events->dispatch('cart.removing', $cartItem);
|
||||||
|
|
||||||
$this->session->put($this->instance, $content);
|
$this->session->put($this->instance, $content);
|
||||||
|
|
||||||
|
$this->events->dispatch('cart.removed', $cartItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user