/** * Copys all data from a given product item. * * @param \Aimeos\MShop\Product\Item\Iface $product Product item to copy from */ public function copyFrom(\Aimeos\MShop\Product\Item\Iface $product) { $this->setProductCode($product->getCode()); $this->setProductId($product->getId()); $this->setType($product->getType()); $this->setName($product->getName()); $items = $product->getRefItems('supplier', 'default', 'default'); if (($item = reset($items)) !== false) { $this->setSupplierCode($item->getCode()); } $items = $product->getRefItems('media', 'default', 'default'); if (($item = reset($items)) !== false) { $this->setMediaUrl($item->getPreview()); } $this->setModified(); return $this; }
/** * 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); } }