/** * Copys all data from a given product item. * * @param MShop_Product_Item_Interface $product Product item to copy from */ public function copyFrom(MShop_Product_Item_Interface $product) { $this->setName($product->getName()); $this->setType($product->getType()); $this->setSupplierCode($product->getSupplierCode()); $this->setProductCode($product->getCode()); $this->setProductId($product->getId()); $items = $product->getRefItems('media', 'default', 'default'); if (($item = reset($items)) !== false) { $this->setMediaUrl($item->getUrl()); } $this->setModified(); }
/** * Edits the changed product to the basket if it's in stock. * * @param MShop_Order_Item_Base_Product_Interface $product Old order product from basket * @param MShop_Product_Item_Interface $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 Controller_Frontend_Basket_Exception If there's not enough stock available */ private function _editProductInStock(MShop_Order_Item_Base_Product_Interface $product, MShop_Product_Item_Interface $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->_basket->deleteProduct($position); if ($stocklevel === null || $stocklevel > 0) { $this->_basket->addProduct($product, $position); $this->_domainManager->setSession($this->_basket); } if ($stocklevel !== null && $stocklevel < $quantity) { $msg = sprintf('There are not enough products "%1$s" in stock', $productItem->getName()); throw new Controller_Frontend_Basket_Exception($msg); } }