Пример #1
0
 /**
  * Edits the changed product to the basket if it's in stock.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $product Old order product from basket
  * @param \Aimeos\MShop\Product\Item\Iface $productItem Product item that belongs to the order product
  * @param integer $quantity New product quantity
  * @param integer $position Position of the old order product in the basket
  * @param array Associative list of options
  * @throws \Aimeos\Controller\Frontend\Basket\Exception If there's not enough stock available
  */
 protected function editProductInStock(\Aimeos\MShop\Order\Item\Base\Product\Iface $product, \Aimeos\MShop\Product\Item\Iface $productItem, $quantity, $position, array $options)
 {
     $stocklevel = null;
     if (!isset($options['stock']) || $options['stock'] != false) {
         $stocklevel = $this->getStockLevel($productItem->getId(), $product->getWarehouseCode());
     }
     $product->setQuantity($stocklevel !== null && $stocklevel > 0 ? min($stocklevel, $quantity) : $quantity);
     $this->get()->deleteProduct($position);
     if ($stocklevel === null || $stocklevel > 0) {
         $this->get()->addProduct($product, $position);
     }
     if ($stocklevel !== null && $stocklevel < $quantity) {
         $msg = sprintf('There are not enough products "%1$s" in stock', $productItem->getName());
         throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
     }
 }