Пример #1
0
 /**
  * Returns the actual price for the given order product.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $orderProduct Ordered product
  * @param array $refPrices Prices associated to the original product
  * @param \Aimeos\MShop\Attribute\Item\Iface[] $attributes Attribute items with prices
  * @param integer $pos Position of the product in the basket
  * @return \Aimeos\MShop\Price\Item\Iface Price item including the calculated price
  */
 private function getPrice(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderProduct, array $refPrices, array $attributes, $pos)
 {
     $context = $this->getContext();
     // fetch prices of selection/parent products
     if (empty($refPrices)) {
         $productManager = \Aimeos\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 \Aimeos\MShop\Plugin\Provider\Exception($msg, -1, null, $codes);
     }
     $priceManager = \Aimeos\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;
 }
Пример #2
0
 /**
  * Compares the properties of the given order product item with its own ones.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $item Order product item
  * @return boolean True if the item properties are equal, false if not
  * @since 2014.09
  */
 public function compare(\Aimeos\MShop\Order\Item\Base\Product\Iface $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;
 }
Пример #3
0
 /**
  * Checks if a order product contains all required values.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $item Order product item
  * @throws \Aimeos\MShop\Exception if the price item or product code is missing
  */
 protected function checkProduct(\Aimeos\MShop\Order\Item\Base\Product\Iface $item)
 {
     if ($item->getProductCode() === '') {
         throw new \Aimeos\MShop\Order\Exception(sprintf('Product does not contain all required values. Product code for item not available.'));
     }
 }