/** * @param CartPositionInterface $position * @param int $quantity */ public function put($position, $quantity = 1) { $id = $position->getId(); if (isset($this->_positions[$id])) { $this->_positions[$id]->setQuantity($this->_positions[$id]->getQuantity() + $quantity); } else { $position->setQuantity($quantity); $this->_positions[$id] = $position; } $this->trigger(self::EVENT_POSITION_PUT, new CartActionEvent(['action' => CartActionEvent::ACTION_POSITION_PUT, 'position' => $this->_positions[$id]])); $this->trigger(self::EVENT_CART_CHANGE, new CartActionEvent(['action' => CartActionEvent::ACTION_POSITION_PUT, 'position' => $this->_positions[$id]])); $qty = $this->_positions[$id]->getQuantity(); $this->saveToDb($position, $qty, 1); if ($this->storeInSession) { $this->saveToSession(); } }
/** * @param CartPositionInterface $position * @param int $quantity */ public function put($position, $quantity = 1) { if (isset($this->_positions[$position->getId()])) { $this->_positions[$position->getId()]->setQuantity($this->_positions[$position->getId()]->getQuantity() + $quantity); } else { $position->setQuantity($quantity); $this->_positions[$position->getId()] = $position; } $this->trigger(self::EVENT_POSITION_PUT, new Event(['data' => $this->_positions[$position->getId()]])); $this->trigger(self::EVENT_CART_CHANGE, new Event(['data' => ['action' => 'put', 'position' => $this->_positions[$position->getId()]]])); if ($this->storeInSession) { $this->saveToSession(); } }