예제 #1
0
 /**
  * Sets quantity to cartLine
  *
  * If quantity is higher than item stock, throw exception
  *
  * This method dispatches all Cart Check and Load events
  *
  * @param CartLineInterface $cartLine Cart line
  * @param integer           $quantity CartLine quantity to set
  *
  * @return $this self Object
  */
 public function setCartLineQuantity(CartLineInterface $cartLine, $quantity)
 {
     $cart = $cartLine->getCart();
     if (!$cart instanceof CartInterface) {
         return $this;
     }
     /**
      * If $quantity is an integer and is less or equal than 0, means that
      * full line must be removed.
      *
      * Otherwise, $quantity can have two values:
      * * null or false - Quantity is not affected
      * * integer higher than 0, quantity is edited and all changes are
      *   recalculated.
      */
     if (is_int($quantity) && $quantity <= 0) {
         $this->silentRemoveLine($cart, $cartLine);
     } elseif (is_int($quantity)) {
         $cartLine->setQuantity($quantity);
         $this->cartLineEventDispatcher->dispatchCartLineOnEditEvent($cart, $cartLine);
     } else {
         /**
          * Nothing to do here. Quantity value is not an integer, so will not
          * be treated as such
          */
         return $this;
     }
     $this->cartEventDispatcher->dispatchCartLoadEvents($cart);
     return $this;
 }
예제 #2
0
 /**
  * Adds cartLine to Cart.
  *
  * This method dispatches all Cart Check and Load events
  * It should NOT be used to add a Purchasable to a Cart,
  * by manually passing a newly crafted CartLine, since
  * no product duplication check is performed: in that
  * case CartManager::addProduct should be used
  *
  * @param CartInterface     $cart     Cart
  * @param CartLineInterface $cartLine Cart line
  *
  * @return $this Self object
  */
 private function addLine(CartInterface $cart, CartLineInterface $cartLine)
 {
     $cartLine->setCart($cart);
     $cart->addCartLine($cartLine);
     $this->cartLineEventDispatcher->dispatchCartLineOnAddEvent($cart, $cartLine);
     $this->cartEventDispatcher->dispatchCartLoadEvents($cart);
     return $this;
 }