/** * Checks for the product limits when the configuration contains limits per currency. * * @param \Aimeos\MShop\Order\Item\Base\Iface $order Basket object * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $value Order product item * @throws \Aimeos\MShop\Plugin\Provider\Exception If one limit is exceeded */ protected function checkWithCurrency(\Aimeos\MShop\Order\Item\Base\Iface $order, \Aimeos\MShop\Order\Item\Base\Product\Iface $value) { $config = $this->getItemBase()->getConfig(); $currencyId = $value->getPrice()->getCurrencyId(); if (isset($config['single-value-max'][$currencyId]) && $value->getPrice()->getValue() * $value->getQuantity() > (double) $config['single-value-max'][$currencyId]) { $msg = $this->getContext()->getI18n()->dt('mshop', 'The maximum product value is %1$s'); throw new \Aimeos\MShop\Plugin\Provider\Exception(sprintf($msg, $config['single-value-max'][$currencyId])); } 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 = $this->getContext()->getI18n()->dt('mshop', 'The maximum value of all products is %1$s'); throw new \Aimeos\MShop\Plugin\Provider\Exception(sprintf($msg, $config['total-value-max'][$currencyId])); } } }
/** * Adds the bundled products to the order product item. * * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem Order product item * @param \Aimeos\MShop\Product\Item\Iface $productItem Bundle product item * @param array $variantAttributeIds List of product variant attribute IDs * @param string $warehouse */ protected function addBundleProducts(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, $warehouse) { $quantity = $orderBaseProductItem->getQuantity(); $products = $subProductIds = $orderProducts = array(); $orderProductManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product'); foreach ($productItem->getRefItems('product', null, 'default') as $item) { $subProductIds[] = $item->getId(); } if (count($subProductIds) > 0) { $productManager = \Aimeos\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); }
/** * 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; }