public bool
correctTotalItems
(mixed &$total, mixed &$shippingCosts, mixed &$paymentCosts, mixed $options = array())
/**
*
* @param unknown $total
* @param unknown $shippingCosts
* @param unknown $paymentCosts
* @param array $options - set specific options - this function is called twice so in second loop just set specific option (e.g. to not create brutto currency again)
* @return boolean
*/
public function correctTotalItems(&$total, &$shippingCosts, &$paymentCosts, $options = array())
{
if (!isset($total[0]['brutto'])) {
return false;
}
$price = new PhocacartPrice();
//$paramsC = PhocacartUtils::getComponentParameters();
//$rounding_calculation = $paramsC->get( 'rounding_calculation', 1 );
//$rounding_calculation_total = $paramsC->get( 'rounding_calculation_total', 2 );
//$currencyRate = PhocacartCurrency::getCurrentCurrencyRateIfNotDefault();
//$currency = PhocacartCurrency::getCurrency();
//$cr = $currency->exchange_rate;
$cr = PhocacartCurrency::getCurrentCurrencyRateIfNotDefault();
$totalDC = 0;
// total in default currency
$totalOR = 0;
// total in order currency
// Subtotal
if (isset($total[1]['netto'])) {
$totalDC += $price->roundPrice($total[1]['netto']);
$totalOR += $price->roundPrice($total[1]['netto'] * $cr);
}
// - Reward points
if (isset($total[5]['dnetto'])) {
$totalDC -= $price->roundPrice($total[5]['dnetto']);
$totalOR -= $price->roundPrice($total[5]['dnetto'] * $cr);
}
// - Product Discount
if (isset($total[2]['dnetto'])) {
$totalDC -= $price->roundPrice($total[2]['dnetto']);
$totalOR -= $price->roundPrice($total[2]['dnetto'] * $cr);
}
// - Discount cart
if (isset($total[3]['dnetto'])) {
$totalDC -= $price->roundPrice($total[3]['dnetto']);
$totalOR -= $price->roundPrice($total[3]['dnetto'] * $cr);
}
// - Coupon cart
if (isset($total[4]['dnetto'])) {
$totalDC -= $price->roundPrice($total[4]['dnetto']);
$totalOR -= $price->roundPrice($total[4]['dnetto'] * $cr);
}
// + VAT
if (!empty($total[0]['tax'])) {
foreach ($total[0]['tax'] as $k => $v) {
$totalDC += $price->roundPrice($v['tax']);
$totalOR += $price->roundPrice($v['tax'] * $cr);
}
}
// + Shipping Costs
if (isset($shippingCosts['brutto'])) {
$shippingCosts['bruttorounded'] = $price->roundPrice($shippingCosts['brutto']);
$totalDC += $price->roundPrice($shippingCosts['brutto']);
$totalOR += $price->roundPrice($shippingCosts['brutto'] * $cr);
}
// + Payment Costs
if (isset($paymentCosts['brutto'])) {
$paymentCosts['bruttorounded'] = $price->roundPrice($paymentCosts['brutto']);
$totalDC += $price->roundPrice($paymentCosts['brutto']);
$totalOR += $price->roundPrice($paymentCosts['brutto'] * $cr);
}
// ------------------------
// 1) NO ROUNDING - CORRECTION ONLY
// ------------------------
// 1a) CORRECT BRUTTO - DEFAULT CURRENCY
$diff = $total[0]['brutto'] - $totalDC;
if (!($price->roundPrice($diff) > -0.01 && $price->roundPrice($diff) < 0.01)) {
$total[0]['rounding'] = $price->roundPrice($diff);
} else {
$total[0]['rounding'] = 0;
}
// 1b) CORRECT BRUTTO - ORDER CURRENCY
if ($cr > 1 || $cr < 1) {
if (isset($options['brutto_currency_set']) && isset($options['brutto_currency_set']) == 1) {
$totalBruttoCurrency = $price->roundPrice($total[0]['brutto_currency']);
} else {
$totalBruttoCurrency = $price->roundPrice($total[0]['brutto'] * $cr);
$total[0]['brutto_currency'] = $totalBruttoCurrency;
}
$diff = $price->roundPrice($totalBruttoCurrency) - $price->roundPrice($totalOR);
if (!($price->roundPrice($diff) > -0.01 && $price->roundPrice($diff) < 0.01)) {
$total[0]['rounding_currency'] = $price->roundPrice($diff);
} else {
$total[0]['rounding_currency'] = 0;
}
return true;
}
}