Example #1
0
 /**
  * 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]));
         }
     }
 }
Example #2
0
 /**
  * Calculates and returns the current price for the given order product and product prices.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $product Ordered product item
  * @param \Aimeos\MShop\Price\Item\Iface[] $prices List of price items
  * @param integer $quantity New product quantity
  * @return \Aimeos\MShop\Price\Item\Iface Price item with calculated price
  */
 protected function calcPrice(\Aimeos\MShop\Order\Item\Base\Product\Iface $product, array $prices, $quantity)
 {
     $context = $this->getContext();
     if (empty($prices)) {
         $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product');
         $prices = $manager->getItem($product->getProductId(), array('price'))->getRefItems('price', 'default');
     }
     $priceManager = \Aimeos\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;
 }
Example #3
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;
 }
Example #4
0
 /**
  * Adds attribute items to an array.
  *
  * @param \Aimeos\MShop\Common\Item\Iface $item Item containing the properties to be added as attributes
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $product Product containing attributes
  * @param Array $properties List of item properties to be converted
  * @return Array List of attributes
  */
 protected function addAttributes(\Aimeos\MShop\Common\Item\Iface $item, \Aimeos\MShop\Order\Item\Base\Product\Iface $product, array $properties)
 {
     $attributeList = $product->getAttributes();
     $itemProperties = $item->toArray();
     foreach ($properties as $code) {
         if (array_key_exists($code, $itemProperties) && $product->getAttribute($code, $this->type) === null) {
             $new = $this->orderAttrManager->createItem();
             $new->setCode($code);
             $new->setType($this->type);
             $new->setValue($itemProperties[$code]);
             $attributeList[] = $new;
         }
     }
     return $attributeList;
 }
 /**
  * Returns the variant attributes and updates the price list if necessary.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem Order product item
  * @param \Aimeos\MShop\Product\Item\Iface &$productItem Product item which is replaced if necessary
  * @param array &$prices List of product prices that will be updated if necessary
  * @param array $variantAttributeIds List of product variant attribute IDs
  * @param array $options Associative list of options
  * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface[] List of order product attributes
  * @throws \Aimeos\Controller\Frontend\Basket\Exception If no product variant is found
  */
 protected function getVariantDetails(\Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, \Aimeos\MShop\Product\Item\Iface &$productItem, array &$prices, array $variantAttributeIds, array $options)
 {
     $attr = array();
     $productItems = $this->getProductVariants($productItem, $variantAttributeIds);
     if (count($productItems) > 1) {
         $msg = sprintf('No unique article found for selected attributes and product ID "%1$s"', $productItem->getId());
         throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
     } else {
         if (($result = reset($productItems)) !== false) {
             $productItem = $result;
             $orderBaseProductItem->setProductCode($productItem->getCode());
             $subprices = $productItem->getRefItems('price', 'default', 'default');
             if (!empty($subprices)) {
                 $prices = $subprices;
             }
             $submedia = $productItem->getRefItems('media', 'default', 'default');
             if (($mediaItem = reset($submedia)) !== false) {
                 $orderBaseProductItem->setMediaUrl($mediaItem->getPreview());
             }
             $orderProductAttrManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'order/base/product/attribute');
             $variantAttributes = $productItem->getRefItems('attribute', null, 'variant');
             foreach ($this->getAttributes(array_keys($variantAttributes), array('text')) as $attrItem) {
                 $orderAttributeItem = $orderProductAttrManager->createItem();
                 $orderAttributeItem->copyFrom($attrItem);
                 $orderAttributeItem->setType('variant');
                 $attr[] = $orderAttributeItem;
             }
         } else {
             if (!isset($options['variant']) || $options['variant'] != false) {
                 $msg = sprintf('No article found for selected attributes and product ID "%1$s"', $productItem->getId());
                 throw new \Aimeos\Controller\Frontend\Basket\Exception($msg);
             }
         }
     }
     return $attr;
 }
Example #6
0
 /**
  * Tests if the given product is similar to an existing one.
  * Similarity is described by the equality of properties so the quantity of
  * the existing product can be updated.
  *
  * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $item Order product item
  * @return integer Positon of the same product in the product list
  * @throws \Aimeos\MShop\Order\Exception If no similar item was found
  */
 protected function getSameProduct(\Aimeos\MShop\Order\Item\Base\Product\Iface $item)
 {
     $attributeMap = array();
     foreach ($item->getAttributes() as $attributeItem) {
         $attributeMap[$attributeItem->getCode()] = $attributeItem;
     }
     foreach ($this->products as $position => $product) {
         if ($product->compare($item) === false) {
             continue;
         }
         $prodAttributes = $product->getAttributes();
         if (count($prodAttributes) !== count($attributeMap)) {
             continue;
         }
         foreach ($prodAttributes as $attribute) {
             if (array_key_exists($attribute->getCode(), $attributeMap) === false || $attributeMap[$attribute->getCode()]->getValue() != $attribute->getValue()) {
                 continue 2;
                 // jump to outer loop
             }
         }
         return $position;
     }
     return false;
 }
Example #7
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;
 }
Example #8
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.'));
     }
 }