/**
  * Updates the position in the shopping cart
  * If the position was previously added, then it will be updated in shopping cart,
  * if the position was not previously in the cart, it will be added there.
  * If the count of less than 1, the position will be deleted.
  *
  * @param IECartPosition $position
  * @param int $quantity
  */
 public function update(CartPosition $position, $quantity)
 {
     if (!$position instanceof Component) {
         throw new InvalidArgumentException('invalid argument 1, product must implement CComponent interface');
     }
     $key = $position->getId();
     $position->attachBehavior("CartPosition", new CartPositionBehaviour());
     $position->setRefresh($this->refresh);
     $position->setQuantity($quantity);
     if ($position->getQuantity() < 1) {
         $this->remove($key);
     } else {
         parent::add($key, $position);
     }
     $this->applyDiscounts();
     $this->onUpdatePoistion(new Event($this));
     $this->saveState();
 }