/** * 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; }
/** * Calculates and returns the current price for the given order product and product prices. * * @param MShop_Order_Item_Base_Product_Interface $product Ordered product item * @param MShop_Price_Item_Interface[] $prices List of price items * @param integer $quantity New product quantity * @return MShop_Price_Item_Interface Price item with calculated price */ private function _calcPrice(MShop_Order_Item_Base_Product_Interface $product, array $prices, $quantity) { $context = $this->_getContext(); if (empty($prices)) { $parentItem = $this->_getDomainItem('product', 'product.id', $product->getProductId(), array('price')); $prices = $parentItem->getRefItems('price', 'default'); } $priceManager = MShop_Factory::createManager($context, 'price'); $price = $priceManager->getLowestPrice($prices, $quantity); foreach ($this->_getAttributeItems($product->getAttributes()) as $attrItem) { $prices = $attrItem->getRefItems('price', 'default'); if (count($prices) > 0) { $attrPrice = $priceManager->getLowestPrice($prices, $quantity); $price->addItem($attrPrice); } } // remove product rebate of original price in favor to rebates granted for the order $price->setRebate('0.00'); return $price; }