Skip to content

Commit

Permalink
Merge pull request #44 from Beaudinn/larastores
Browse files Browse the repository at this point in the history
Unable to listen to 'conditions' changing
  • Loading branch information
darryldecode committed Dec 15, 2015
2 parents c6ee561 + b90c3cb commit bd7a62c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Darryldecode/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,14 @@ public function add($id, $name = null, $price = null, $quantity = null, $attribu
// if the item is already in the cart we will just update it
if( $cart->has($id) )
{
$this->events->fire($this->getInstanceName().'.updating', array($item, $this));

$this->update($id, $item);

$this->events->fire($this->getInstanceName().'.updated', array($item, $this));
}
else
{
$this->events->fire($this->getInstanceName().'.adding', array($item, $this));

$this->addRow($id, $item);

$this->events->fire($this->getInstanceName().'.added', array($item, $this));
}

return $this;
Expand All @@ -190,6 +185,8 @@ public function add($id, $name = null, $price = null, $quantity = null, $attribu
*/
public function update($id, $data)
{
$this->events->fire($this->getInstanceName().'.updating', array($data, $this));

$cart = $this->getContent();

$item = $cart->pull($id);
Expand Down Expand Up @@ -238,6 +235,8 @@ public function update($id, $data)
$cart->put($id, $item);

$this->save($cart);

$this->events->fire($this->getInstanceName().'.updated', array($item, $this));
}

/**
Expand Down Expand Up @@ -641,11 +640,15 @@ protected function validate($item)
*/
protected function addRow($id, $item)
{
$this->events->fire($this->getInstanceName().'.adding', array($item, $this));

$cart = $this->getContent();

$cart->put($id, new ItemCollection($item));

$this->save($cart);

$this->events->fire($this->getInstanceName().'.added', array($item, $this));
}

/**
Expand Down

0 comments on commit bd7a62c

Please sign in to comment.