コード例 #1
0
ファイル: Base.php プロジェクト: aimeos/aimeos-core
 /**
  * Compares the properties of the given price item with its own one.
  *
  * This method compare only the essential price properties:
  * * Value
  * * Costs
  * * Rebate
  * * Tax rate
  * * Tax flag
  * * Quantity
  * * Currency ID
  *
  * All other item properties are not compared.
  *
  * @param \Aimeos\MShop\Price\Item\Iface $price Price item to compare with
  * @return boolean True if equal, false if not
  * @since 2014.09
  */
 public function compare(\Aimeos\MShop\Price\Item\Iface $price)
 {
     if ($this->getValue() === $price->getValue() && $this->getCosts() === $price->getCosts() && $this->getRebate() === $price->getRebate() && $this->getTaxRate() === $price->getTaxRate() && $this->getTaxFlag() === $price->getTaxFlag() && $this->getQuantity() === $price->getQuantity() && $this->getCurrencyId() === $price->getCurrencyId()) {
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: Shipping.php プロジェクト: aimeos/aimeos-core
 /**
  * Tests if the shipping threshold is reached and updates the price accordingly
  *
  * @param \Aimeos\MShop\Order\Item\Base\Iface $order Basket object
  * @param \Aimeos\MShop\Price\Item\Iface $price Delivery price item
  * @param array $threshold Associative list of currency/threshold pairs
  */
 protected function checkThreshold(\Aimeos\MShop\Order\Item\Base\Iface $order, \Aimeos\MShop\Price\Item\Iface $price, array $threshold)
 {
     $currency = $price->getCurrencyId();
     if (!isset($threshold[$currency])) {
         return;
     }
     $sum = \Aimeos\MShop\Factory::createManager($this->getContext(), 'price')->createItem();
     foreach ($order->getProducts() as $product) {
         $sum->addItem($product->getPrice(), $product->getQuantity());
     }
     if ($sum->getValue() + $sum->getRebate() >= $threshold[$currency] && $price->getCosts() > '0.00') {
         $price->setRebate($price->getCosts());
         $price->setCosts('0.00');
     } else {
         if ($sum->getValue() + $sum->getRebate() < $threshold[$currency] && $price->getRebate() > '0.00') {
             $price->setCosts($price->getRebate());
             $price->setRebate('0.00');
         }
     }
 }
コード例 #3
0
ファイル: BasketLimits.php プロジェクト: mvnp/aimeos-core
 /**
  * Checks for the configured basket limits.
  *
  * @param \Aimeos\MShop\Price\Item\Iface $sum Total sum of all product price items
  * @param integer $count Total number of products in the basket
  * @throws \Aimeos\MShop\Plugin\Provider\Exception If one of the minimum or maximum limits is exceeded
  */
 protected function checkLimits(\Aimeos\MShop\Price\Item\Iface $sum, $count)
 {
     $currencyId = $sum->getCurrencyId();
     $config = $this->getItemBase()->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 \Aimeos\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 \Aimeos\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 \Aimeos\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 \Aimeos\MShop\Plugin\Provider\Exception($msg);
     }
 }
コード例 #4
0
ファイル: Standard.php プロジェクト: aimeos/aimeos-core
 /**
  * Add the given price to the current one.
  *
  * @param \Aimeos\MShop\Price\Item\Iface $item Price item which should be added
  * @param integer $quantity Number of times the Price should be added
  * @return \Aimeos\MShop\Price\Item\Iface Price item for chaining method calls
  */
 public function addItem(\Aimeos\MShop\Price\Item\Iface $item, $quantity = 1)
 {
     if ($item->getCurrencyId() != $this->getCurrencyId()) {
         $msg = 'Price can not be added. Currency ID "%1$s" of price item and currently used currency ID "%2$s" does not match.';
         throw new \Aimeos\MShop\Price\Exception(sprintf($msg, $item->getCurrencyId(), $this->getCurrencyId()));
     }
     if ($this === $item) {
         $item = clone $item;
     }
     $taxValue = $this->getTaxValue();
     $this->setQuantity(1);
     $this->setValue($this->getValue() + $item->getValue() * $quantity);
     $this->setCosts($this->getCosts() + $item->getCosts() * $quantity);
     $this->setRebate($this->getRebate() + $item->getRebate() * $quantity);
     $this->setTaxValue($taxValue + $item->getTaxValue() * $quantity);
     return $this;
 }
コード例 #5
0
 /**
  * Creates the order product attribute items from the given attribute IDs and updates the price item if necessary.
  *
  * @param \Aimeos\MShop\Price\Item\Iface $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
  * @param array $attributeValues Associative list of attribute IDs as keys and their codes as values
  * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface
  */
 protected function createOrderProductAttributes(\Aimeos\MShop\Price\Item\Iface $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 = \Aimeos\MShop\Factory::createManager($context, 'price');
     $orderProductAttributeManager = \Aimeos\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;
 }
コード例 #6
0
ファイル: BasketLimits.php プロジェクト: aimeos/aimeos-core
 /**
  * Checks for the configured basket limits.
  *
  * @param \Aimeos\MShop\Price\Item\Iface $sum Total sum of all product price items
  * @param array $config Associative list of configuration key/value pairs
  * @throws \Aimeos\MShop\Plugin\Provider\Exception If one of the minimum or maximum limits is exceeded
  */
 protected function checkLimitsValue(array $config, \Aimeos\MShop\Price\Item\Iface $sum)
 {
     $currencyId = $sum->getCurrencyId();
     if (isset($config['min-value'][$currencyId]) && $sum->getValue() + $sum->getRebate() < $config['min-value'][$currencyId]) {
         $msg = $this->getContext()->getI18n()->dt('mshop', 'The minimum basket value of %1$s isn\'t reached');
         throw new \Aimeos\MShop\Plugin\Provider\Exception(sprintf($msg, $config['min-value'][$currencyId]));
     }
     if (isset($config['max-value'][$currencyId]) && $sum->getValue() + $sum->getRebate() > $config['max-value'][$currencyId]) {
         $msg = $this->getContext()->getI18n()->dt('mshop', 'The maximum basket value of %1$s is exceeded');
         throw new \Aimeos\MShop\Plugin\Provider\Exception(sprintf($msg, $config['max-value'][$currencyId]));
     }
 }
コード例 #7
0
ファイル: Base.php プロジェクト: skyheights/aimeos-core
 /**
  * Returns the calculated amount of the price item
  *
  * @param \Aimeos\MShop\Price\Item\Iface $price Price item
  * @return string Formatted money amount
  */
 protected function getAmount(\Aimeos\MShop\Price\Item\Iface $price)
 {
     $amount = $price->getValue() + $price->getCosts();
     if ($price->getTaxFlag() === false) {
         $amount += $price->getTaxValue();
     }
     return number_format($amount, 2, '.', '');
 }
コード例 #8
0
ファイル: Base.php プロジェクト: aimeos/aimeos-core
 /**
  * Returns the calculated amount of the price item
  *
  * @param \Aimeos\MShop\Price\Item\Iface $price Price item
  * @param boolean $costs Include costs per item
  * @param boolean $tax Include tax
  * @return string Formatted money amount
  */
 protected function getAmount(\Aimeos\MShop\Price\Item\Iface $price, $costs = true, $tax = true)
 {
     $amount = $price->getValue();
     if ($costs === true) {
         $amount += $price->getCosts();
     }
     if ($tax === true && $price->getTaxFlag() === false) {
         $tmp = clone $price;
         if ($costs === false) {
             $tmp->clear();
             $tmp->setValue($price->getValue());
             $tmp->setTaxRate($price->getTaxRate());
             $tmp->setQuantity($price->getQuantity());
         }
         $amount += $tmp->getTaxValue();
     }
     return number_format($amount, 2, '.', '');
 }