Пример #1
0
 /**
  * Checks for the product limits when the configuration contains limits per currency.
  *
  * @param MShop_Order_Item_Base_Interface $order Basket object
  * @param MShop_Order_Item_Base_Product_Interface $value Order product item
  * @throws MShop_Plugin_Provider_Exception If one limit is exceeded
  */
 protected function _checkWithCurrency(MShop_Order_Item_Base_Interface $order, MShop_Order_Item_Base_Product_Interface $value)
 {
     $config = $this->_getItem()->getConfig();
     $currencyId = $value->getPrice()->getCurrencyId();
     if (isset($config['single-value-max'][$currencyId]) && $value->getPrice()->getValue() * $value->getQuantity() > (double) $config['single-value-max'][$currencyId]) {
         $msg = sprintf('The maximum product value is %1$s', $config['single-value-max'][$currencyId]);
         throw new MShop_Plugin_Provider_Exception($msg);
     }
     if (isset($config['total-value-max'][$currencyId])) {
         $price = clone $value->getPrice();
         $price->setValue($price->getValue() * $value->getQuantity());
         foreach ($order->getProducts() as $product) {
             $price->addItem($product->getPrice(), $product->getQuantity());
         }
         if ((double) $price->getValue() > (double) $config['total-value-max'][$currencyId]) {
             $msg = sprintf('The maximum value of all products is %1$s', $config['total-value-max'][$currencyId]);
             throw new MShop_Plugin_Provider_Exception($msg);
         }
     }
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * Adds the bundled products to the order product item.
  *
  * @param MShop_Order_Item_Base_Product_Interface $orderBaseProductItem Order product item
  * @param MShop_Product_Item_Interface $productItem Bundle product item
  * @param array $variantAttributeIds List of product variant attribute IDs
  * @param string $warehouse
  */
 protected function _addBundleProducts(MShop_Order_Item_Base_Product_Interface $orderBaseProductItem, MShop_Product_Item_Interface $productItem, array $variantAttributeIds, $warehouse)
 {
     $quantity = $orderBaseProductItem->getQuantity();
     $products = $subProductIds = $orderProducts = array();
     $orderProductManager = MShop_Factory::createManager($this->_getContext(), 'order/base/product');
     foreach ($productItem->getRefItems('product', null, 'default') as $item) {
         $subProductIds[] = $item->getId();
     }
     if (count($subProductIds) > 0) {
         $productManager = MShop_Factory::createManager($this->_getContext(), 'product');
         $search = $productManager->createSearch(true);
         $expr = array($search->compare('==', 'product.id', $subProductIds), $search->getConditions());
         $search->setConditions($search->combine('&&', $expr));
         $products = $productManager->searchItems($search, array('attribute', 'media', 'price', 'text'));
     }
     foreach ($products as $product) {
         $prices = $product->getRefItems('price', 'default', 'default');
         $orderProduct = $orderProductManager->createItem();
         $orderProduct->copyFrom($product);
         $orderProduct->setWarehouseCode($warehouse);
         $orderProduct->setPrice($this->_calcPrice($orderProduct, $prices, $quantity));
         $orderProducts[] = $orderProduct;
     }
     $orderBaseProductItem->setProducts($orderProducts);
 }