mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
feat: database support
This commit is contained in:
+18
-13
@@ -15,11 +15,6 @@ class Cart
|
||||
|
||||
protected $instanceName;
|
||||
|
||||
protected $customStorage = false;
|
||||
protected $sessionKey;
|
||||
protected $sessionKeyCartItems;
|
||||
protected $sessionKeyCartConditions;
|
||||
|
||||
protected $config;
|
||||
|
||||
protected $currentItemId;
|
||||
@@ -168,7 +163,7 @@ public function add(
|
||||
*/
|
||||
public function update(int|string $id, array $data): bool
|
||||
{
|
||||
if ($this->fireEvent('Updating', $data) === false) {
|
||||
if ($this->fireEvent('Updating', 'item', $data) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -201,7 +196,7 @@ public function update(int|string $id, array $data): bool
|
||||
|
||||
$this->save($cart);
|
||||
|
||||
$this->fireEvent('Updated', $item);
|
||||
$this->fireEvent('Updated', 'item', $item);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -260,7 +255,7 @@ public function remove($id)
|
||||
{
|
||||
$cart = $this->getContent();
|
||||
|
||||
if ($this->fireEvent('Removing', $id) === false) {
|
||||
if ($this->fireEvent('Removing', 'item', $id) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -268,7 +263,7 @@ public function remove($id)
|
||||
|
||||
$this->save($cart);
|
||||
|
||||
$this->fireEvent('Removed', $id);
|
||||
$this->fireEvent('Removed', 'item', $id);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -714,7 +709,7 @@ protected function validate($item)
|
||||
*/
|
||||
protected function addItem($id, $item)
|
||||
{
|
||||
if ($this->fireEvent('Adding', $item) === false) {
|
||||
if ($this->fireEvent('Adding', 'item', $item) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -724,7 +719,7 @@ protected function addItem($id, $item)
|
||||
|
||||
$this->save($cart);
|
||||
|
||||
$this->fireEvent('Added', $item);
|
||||
$this->fireEvent('Added', 'item', $item);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -815,9 +810,19 @@ public function setDecimals($decimals)
|
||||
$this->decimals = $decimals;
|
||||
}
|
||||
|
||||
protected function fireEvent($name, $value = [])
|
||||
protected function fireEvent($name, $type = null, $data = null)
|
||||
{
|
||||
return $this->events->dispatch('LaravelCart.' . $name, array_values([$value, $this]), true);
|
||||
$eventData = [
|
||||
'session_key' => $this->session->sessionKey,
|
||||
'session_driver' => $this->session->driver,
|
||||
'session_model' => $this->session->getSessionModel(),
|
||||
];
|
||||
|
||||
if ($type) {
|
||||
$eventData[$type] = $data;
|
||||
}
|
||||
|
||||
return $this->events->dispatch('LaravelCart.' . $name, array_values([$eventData, $this]), true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user