/** * Checks if a order product contains all required values. * * @param MShop_Order_Item_Base_Product_Interface $item Order product item * @throws MShop_Exception if the price item or product code is missing */ protected function _checkProduct(MShop_Order_Item_Base_Product_Interface $item) { if ($item->getProductCode() === '') { throw new MShop_Order_Exception(sprintf('Product does not contain all required values. Product code for item not available.')); } }
/** * Compares the properties of the given order product item with its own ones. * * @param MShop_Order_Item_Base_Product_Interface $item Order product item * @return boolean True if the item properties are equal, false if not * @since 2014.09 */ public function compare(MShop_Order_Item_Base_Product_Interface $item) { if ($this->getFlags() === $item->getFlags() && $this->getName() === $item->getName() && $this->getProductCode() === $item->getProductCode() && $this->getSupplierCode() === $item->getSupplierCode() && $this->getPrice()->compare($item->getPrice()) === true) { return true; } return false; }
/** * Returns the actual price for the given order product. * * @param MShop_Order_Item_Base_Product_Interface $orderProduct Ordered product * @param array $refPrices Prices associated to the original product * @param MShop_Attribute_Item_Interface[] $attributes Attribute items with prices * @param integer $pos Position of the product in the basket * @return MShop_Price_Item_Interface Price item including the calculated price */ private function _getPrice(MShop_Order_Item_Base_Product_Interface $orderProduct, array $refPrices, array $attributes, $pos) { $context = $this->_getContext(); // fetch prices of selection/parent products if (empty($refPrices)) { $productManager = MShop_Factory::createManager($context, 'product'); $product = $productManager->getItem($orderProduct->getProductId(), array('price')); $refPrices = $product->getRefItems('price', 'default', 'default'); } if (empty($refPrices)) { $pid = $orderProduct->getProductId(); $pcode = $orderProduct->getProductCode(); $codes = array('product' => array($pos => 'product.price')); $msg = sprintf('No price for product ID "%1$s" or product code "%2$s" available', $pid, $pcode); throw new MShop_Plugin_Provider_Exception($msg, -1, null, $codes); } $priceManager = MShop_Factory::createManager($context, 'price'); $price = $priceManager->getLowestPrice($refPrices, $orderProduct->getQuantity()); // add prices of product attributes to compute the end price for comparison foreach ($orderProduct->getAttributes() as $orderAttribute) { $attrPrices = array(); $attrId = $orderAttribute->getAttributeId(); if (isset($attributes[$attrId])) { $attrPrices = $attributes[$attrId]->getRefItems('price', 'default', 'default'); } if (!empty($attrPrices)) { $price->addItem($priceManager->getLowestPrice($attrPrices, $orderProduct->getQuantity())); } } // reset product rebates like in the basket controller $price->setRebate('0.00'); return $price; }