diff --git a/CartActionEvent.php b/CartActionEvent.php new file mode 100644 index 0000000..bbd4ac8 --- /dev/null +++ b/CartActionEvent.php @@ -0,0 +1,28 @@ +setQuantity($quantity); $this->_positions[$position->getId()] = $position; } - $this->trigger(self::EVENT_POSITION_PUT, new Event([ - 'data' => $this->_positions[$position->getId()], + $this->trigger(self::EVENT_POSITION_PUT, new CartActionEvent([ + 'action' => CartActionEvent::ACTION_POSITION_PUT, + 'position' => $this->_positions[$position->getId()], ])); - $this->trigger(self::EVENT_CART_CHANGE, new Event([ - 'data' => ['action' => 'put', 'position' => $this->_positions[$position->getId()]], + $this->trigger(self::EVENT_CART_CHANGE, new CartActionEvent([ + 'action' => CartActionEvent::ACTION_POSITION_PUT, + 'position' => $this->_positions[$position->getId()], ])); if ($this->storeInSession) $this->saveToSession(); @@ -137,11 +139,13 @@ public function update($position, $quantity) $position->setQuantity($quantity); $this->_positions[$position->getId()] = $position; } - $this->trigger(self::EVENT_POSITION_UPDATE, new Event([ - 'data' => $this->_positions[$position->getId()], + $this->trigger(self::EVENT_POSITION_UPDATE, new CartActionEvent([ + 'action' => CartActionEvent::ACTION_UPDATE, + 'position' => $this->_positions[$position->getId()], ])); - $this->trigger(self::EVENT_CART_CHANGE, new Event([ - 'data' => ['action' => 'update', 'position' => $this->_positions[$position->getId()]], + $this->trigger(self::EVENT_CART_CHANGE, new CartActionEvent([ + 'action' => CartActionEvent::ACTION_UPDATE, + 'position' => $this->_positions[$position->getId()], ])); if ($this->storeInSession) $this->saveToSession(); @@ -162,11 +166,13 @@ public function remove($position) */ public function removeById($id) { - $this->trigger(self::EVENT_BEFORE_POSITION_REMOVE, new Event([ - 'data' => $this->_positions[$id], + $this->trigger(self::EVENT_BEFORE_POSITION_REMOVE, new CartActionEvent([ + 'action' => CartActionEvent::ACTION_BEFORE_REMOVE, + 'position' => $this->_positions[$id], ])); - $this->trigger(self::EVENT_CART_CHANGE, new Event([ - 'data' => ['action' => 'remove', 'position' => $this->_positions[$id]], + $this->trigger(self::EVENT_CART_CHANGE, new CartActionEvent([ + 'action' => CartActionEvent::ACTION_BEFORE_REMOVE, + 'position' => $this->_positions[$id], ])); unset($this->_positions[$id]); if ($this->storeInSession) @@ -179,8 +185,8 @@ public function removeById($id) public function removeAll() { $this->_positions = []; - $this->trigger(self::EVENT_CART_CHANGE, new Event([ - 'data' => ['action' => 'removeAll'], + $this->trigger(self::EVENT_CART_CHANGE, new CartActionEvent([ + 'action' => CartActionEvent::ACTION_REMOVE_ALL, ])); if ($this->storeInSession) $this->saveToSession(); @@ -223,8 +229,8 @@ public function getPositions() public function setPositions($positions) { $this->_positions = $positions; - $this->trigger(self::EVENT_CART_CHANGE, new Event([ - 'data' => ['action' => 'positions'], + $this->trigger(self::EVENT_CART_CHANGE, new CartActionEvent([ + 'action' => CartActionEvent::ACTION_SET_POSITIONS, ])); if ($this->storeInSession) $this->saveToSession();