Пример #1
0
 /**
  * Updates quantity of selected item by it's key.
  *
  * @param $key      string Item key in the cart.
  * @param $quantity int Quantity to set.
  *
  * @throws Exception When product does not exists or quantity is not numeric.
  */
 public function updateQuantity($key, $quantity)
 {
     if (!$this->hasItem($key)) {
         throw new Exception(__('Item does not exists', 'jigoshop'));
     }
     if (!is_numeric($quantity)) {
         throw new Exception(__('Quantity has to be numeric value', 'jigoshop'));
     }
     if ($quantity <= 0) {
         $this->removeItem($key);
         return;
     }
     $item = $this->getItem($key);
     $product = $item->getProduct();
     if ($product === null || $product->getId() === 0) {
         throw new Exception(__('Product not found', 'jigoshop'));
     }
     if ($product instanceof Product\Purchasable && !$this->checkStock($product, $quantity)) {
         throw new NotEnoughStockException($product->getStock()->getStock());
     }
     parent::updateQuantity($key, $quantity);
 }