/** * Set the Money value * * @param mixed $val Value to set * * @return void */ public function setValue($val) { $defaultCurrency = SilvercartConfig::DefaultCurrency(); if (is_array($val)) { if (empty($val['Currency'])) { $val['Currency'] = $defaultCurrency; } if (!empty($val['Amount'])) { $val['Amount'] = $this->prepareAmount($val['Amount']); } } elseif ($val instanceof Money) { if ($val->getCurrency() != $defaultCurrency && $this->getCurrencyIsReadonly()) { $val->setCurrency($defaultCurrency); } if ($val->getAmount() != '') { $val->setAmount($this->prepareAmount($val->getAmount())); } } parent::setValue($val); }
/** * returns carts net value including all editional costs * * @return Money amount * * @deprecated Use property AmountTotal instead */ public function getAmountNet() { user_error('SilvercartOrder::getAmountNet() is marked as deprecated! Use property AmountTotal instead.', E_USER_ERROR); $amountNet = $this->AmountGrossTotal->getAmount() - $this->Tax->getAmount(); $amountNetObj = new Money(); $amountNetObj->setAmount($amountNet); $amountNetObj->setCurrency(SilvercartConfig::DefaultCurrency()); return $amountNetObj; }
/** * Returns tax amounts included in the shoppingcart separated by tax rates * without fee taxes. * * @param array $excludeModules An array of registered modules that shall not * be taken into account. * @param array $excludeShoppingCartPosition Positions that shall not be counted * * @return ArrayList */ public function getTaxRatesWithoutFeesAndCharges($excludeModules = array(), $excludeShoppingCartPosition = false) { $positions = $this->SilvercartShoppingCartPositions(); $taxes = new ArrayList(); $registeredModules = $this->callMethodOnRegisteredModules('ShoppingCartPositions', array(SilvercartCustomer::currentUser()->getCart(), SilvercartCustomer::currentUser(), true), $excludeModules, $excludeShoppingCartPosition); // products foreach ($positions as $position) { $taxRate = $position->SilvercartProduct()->getTaxRate(); $originalTaxRate = $position->SilvercartProduct()->getTaxRate(true); if (!$taxes->find('Rate', $taxRate)) { $taxes->push(new DataObject(array('Rate' => $taxRate, 'OriginalRate' => $originalTaxRate, 'AmountRaw' => (double) 0.0))); } $taxSection = $taxes->find('Rate', $taxRate); $taxSection->AmountRaw += $position->getTaxAmount(); } // Registered Modules foreach ($registeredModules as $moduleName => $moduleOutput) { foreach ($moduleOutput as $modulePosition) { $taxRate = $modulePosition->TaxRate; if (!$taxes->find('Rate', $taxRate)) { $taxes->push(new DataObject(array('Rate' => $taxRate, 'OriginalRate' => $taxRate, 'AmountRaw' => (double) 0.0))); } $taxSection = $taxes->find('Rate', $taxRate); $taxAmount = $modulePosition->TaxAmount; $taxSection->AmountRaw = round($taxSection->AmountRaw + $taxAmount, 4); } } foreach ($taxes as $tax) { $taxObj = new Money(); $taxObj->setAmount($tax->AmountRaw); $taxObj->setCurrency(SilvercartConfig::DefaultCurrency()); $tax->Amount = $taxObj; } return $taxes; }
/** * Returns the charges and discounts for the shopping cart total 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 16.11.2013 */ public function getChargesAndDiscountsForTotal(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 == 'totalValue') { $excludedPositions = array(); switch ($this->sumModificationValueType) { case 'percent': $amount = $silvercartShoppingCart->getAmountTotal(array(), false, true); $modificationValue = $amount->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++; } 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->getAmountTotal(array(), false, true); } else { $shoppingCartTotal = $silvercartShoppingCart->getAmountTotalNetWithoutVat(array(), false, true); $taxRate = $silvercartShoppingCart->getMostValuableTaxRate(); $handlingCostAmount = round($handlingCostAmount / (100 + $taxRate->Rate) * 100, 4); } if ($handlingCostAmount < 0 && $shoppingCartTotal->getAmount() < $handlingCostAmount * -1) { $handlingCostAmount = $shoppingCartTotal->getAmount() * -1; } $handlingCosts->setAmount($handlingCostAmount); } $this->extend('updateChargesAndDiscountsForTotal', $handlingCosts); if ($handlingCosts->getAmount() == 0) { $handlingCosts = false; } return $handlingCosts; }
/** * price sum of this position * * @param boolean $forSingleProduct Indicates wether the price for the total * quantity of products should be returned * or for one product only. * @param boolean $priceType 'gross' or 'net'. If undefined it'll be automatically chosen. * * @return Money the price sum * * @author Sebastian Diel <*****@*****.**>, * Sascha Koehler <*****@*****.**> * @since 19.11.2014 */ public function getPrice($forSingleProduct = false, $priceType = false) { $priceKey = (string) $forSingleProduct . '-' . (string) $priceType; if (!array_key_exists($priceKey, $this->prices)) { $pluginPriceObj = SilvercartPlugin::call($this, 'overwriteGetPrice', array($forSingleProduct), false, 'DataObject'); if ($pluginPriceObj !== false) { return $pluginPriceObj; } $product = $this->SilvercartProduct(); $price = 0; if ($product && $product->getPrice($priceType)->getAmount()) { if ($forSingleProduct) { $price = $product->getPrice($priceType)->getAmount(); } else { $price = $product->getPrice($priceType)->getAmount() * $this->Quantity; } } $priceObj = new Money(); $priceObj->setAmount($price); $priceObj->setCurrency(SilvercartConfig::DefaultCurrency()); $this->extend('updatePrice', $priceObj); $this->prices[$priceKey] = $priceObj; } return $this->prices[$priceKey]; }