示例#1
0
 /**
  * Checks for the configured basket limits.
  *
  * @param MShop_Price_Item_Interface $sum Total sum of all product price items
  * @param integer $count Total number of products in the basket
  * @throws MShop_Plugin_Provider_Exception If one of the minimum or maximum limits is exceeded
  */
 protected function _checkLimits(MShop_Price_Item_Interface $sum, $count)
 {
     $currencyId = $sum->getCurrencyId();
     $config = $this->_getItem()->getConfig();
     if (isset($config['min-value'][$currencyId]) && $sum->getValue() + $sum->getRebate() < $config['min-value'][$currencyId]) {
         $msg = sprintf('The minimum basket value of %1$s isn\'t reached', $config['min-value'][$currencyId]);
         throw new MShop_Plugin_Provider_Exception($msg);
     }
     if (isset($config['max-value'][$currencyId]) && $sum->getValue() + $sum->getRebate() > $config['max-value'][$currencyId]) {
         $msg = sprintf('The maximum basket value of %1$s is exceeded', $config['max-value'][$currencyId]);
         throw new MShop_Plugin_Provider_Exception($msg);
     }
     if (isset($config['min-products']) && $count < $config['min-products']) {
         $msg = sprintf('The minimum product quantity of %1$d isn\'t reached', $config['min-products']);
         throw new MShop_Plugin_Provider_Exception($msg);
     }
     if (isset($config['max-products']) && $count > $config['max-products']) {
         $msg = sprintf('The maximum product quantity of %1$d is exceeded', $config['max-products']);
         throw new MShop_Plugin_Provider_Exception($msg);
     }
 }
示例#2
0
 /**
  * Compares the properties of the given price item with its own one.
  *
  * This method compare only the essential price properties:
  * * Value
  * * Costs
  * * Rebate
  * * Taxrate
  * * Quantity
  * * Currency ID
  *
  * All other item properties are not compared.
  *
  * @param MShop_Price_Item_Interface $price Price item to compare with
  * @return boolean True if equal, false if not
  * @since 2014.09
  */
 public function compare(MShop_Price_Item_Interface $price)
 {
     if ($this->getValue() === $price->getValue() && $this->getCosts() === $price->getCosts() && $this->getRebate() === $price->getRebate() && $this->getTaxrate() === $price->getTaxrate() && $this->getQuantity() === $price->getQuantity() && $this->getCurrencyId() === $price->getCurrencyId()) {
         return true;
     }
     return false;
 }
示例#3
0
 /**
  * Creates the order product attribute items from the given attribute IDs and updates the price item if necessary.
  *
  * @param MShop_Price_Item_Interface $price Price item of the ordered product
  * @param string $prodid Unique product ID where the given attributes must be attached to
  * @param integer $quantity Number of products that should be added to the basket
  * @param array $attributeIds List of attributes IDs of the given type
  * @param string $type Attribute type
  * @return array List of items implementing MShop_Order_Item_Product_Attribute_Interface
  */
 protected function _createOrderProductAttributes(MShop_Price_Item_Interface $price, $prodid, $quantity, array $attributeIds, $type, array $attributeValues = array())
 {
     if (empty($attributeIds)) {
         return array();
     }
     $attrTypeId = $this->_getProductListTypeItem('attribute', $type)->getId();
     $this->_checkReferences($prodid, 'attribute', $attrTypeId, $attributeIds);
     $list = array();
     $context = $this->_getContext();
     $priceManager = MShop_Factory::createManager($context, 'price');
     $orderProductAttributeManager = MShop_Factory::createManager($context, 'order/base/product/attribute');
     foreach ($this->_getAttributes($attributeIds) as $id => $attrItem) {
         $prices = $attrItem->getRefItems('price', 'default', 'default');
         if (!empty($prices)) {
             $price->addItem($priceManager->getLowestPrice($prices, $quantity));
         }
         $item = $orderProductAttributeManager->createItem();
         $item->copyFrom($attrItem);
         $item->setType($type);
         if (isset($attributeValues[$id])) {
             $item->setValue($attributeValues[$id]);
         }
         $list[] = $item;
     }
     return $list;
 }