/** * Returns the charges and discounts for the product values for this * payment method. * * @param SilvercartShoppingCart $silvercartShoppingCart The shopping cart object * @param string $priceType 'gross' or 'net' * * @return mixed boolean|DataObject * * @author Sascha Koehler <*****@*****.**>, * Sebastian Diel <*****@*****.**> * @since 13.03.2014 */ public function getChargesAndDiscountsForProducts(SilvercartShoppingCart $silvercartShoppingCart, $priceType = false) { $handlingCosts = new Money(); $handlingCosts->setAmount(0); $handlingCosts->setCurrency(SilvercartConfig::DefaultCurrency()); if ($priceType === false) { $priceType = SilvercartConfig::PriceType(); } if ($this->useSumModification && $this->sumModificationImpact == 'productValue') { $excludedPositions = array(); $shoppingCartAmount = $silvercartShoppingCart->getAmountTotalWithoutFees(array(), false, true); switch ($this->sumModificationValueType) { case 'percent': $modificationValue = $shoppingCartAmount->getAmount() / 100 * $this->sumModificationValue; $index = 1; foreach ($silvercartShoppingCart->SilvercartShoppingCartPositions() as $position) { if ($position->SilvercartProductID > 0 && $position->SilvercartProduct() instanceof SilvercartProduct && $position->SilvercartProduct()->ExcludeFromPaymentDiscounts) { $modificationValue -= $position->getPrice()->getAmount() / 100 * $this->sumModificationValue; $excludedPositions[] = $index; } $index++; } $this->sumModificationLabel .= ' (' . sprintf(_t('SilvercartPaymentMethod.ChargeOrDiscountForAmount'), $shoppingCartAmount->Nice()) . ')'; break; case 'absolute': default: $modificationValue = $this->sumModificationValue; } if (count($excludedPositions) > 0) { if (count($excludedPositions) == 1) { $this->sumModificationLabel .= ' (' . sprintf(_t('SilvercartPaymentMethod.ExcludedPosition'), implode(', ', $excludedPositions)) . ')'; } else { $this->sumModificationLabel .= ' (' . sprintf(_t('SilvercartPaymentMethod.ExcludedPositions'), implode(', ', $excludedPositions)) . ')'; } } if ($this->sumModificationImpactType == 'charge') { $handlingCostAmount = $modificationValue; } else { $handlingCostAmount = "-" . $modificationValue; } if (SilvercartConfig::PriceType() == 'gross') { $shoppingCartTotal = $silvercartShoppingCart->getAmountTotalGrossWithoutFees(array(), false, true); } else { $shoppingCartTotal = $silvercartShoppingCart->getAmountTotalNetWithoutFees(array(), false, true); } if ($handlingCostAmount < 0 && $shoppingCartTotal->getAmount() < $handlingCostAmount * -1) { if ($shoppingCartTotal->getAmount == 0.0) { $handlingCostAmount = 0.0; } else { $handlingCostAmount = $shoppingCartTotal->getAmount() * -1; } } if (SilvercartConfig::PriceType() == 'net') { $taxRate = $silvercartShoppingCart->getMostValuableTaxRate(); if ($taxRate) { $handlingCostAmount = round($handlingCostAmount / (100 + $taxRate->Rate) * 100, 4); } } $handlingCosts->setAmount(round($handlingCostAmount, 2)); } $this->extend('updateChargesAndDiscountsForProducts', $handlingCosts); if ($handlingCosts->getAmount() == 0) { $handlingCosts = false; } return $handlingCosts; }