There were three aspects to this change:
/includes/classes/currencies.php:
Code:
function display_price($products_price, $products_tax, $quantity = 1) {
//-bof-20140729-lat9-Fix rounding error with tax calculation
// return $this->format(zen_add_tax($products_price, $products_tax) * $quantity);
return $this->format (zen_add_tax($products_price * $quantity, $products_tax));
//-eof-20140729-lat9-Fix rounding error ...
}
/includes/classes/order.php:
Code:
//-bof-20151015-lat9-Enable cart->order processing to be cognizant of the order's currency *** 1 of 3 ***
function __construct($order_id = '', $override_currency = false) {
$this->currency = ($override_currency === false) ? $_SESSION['currency'] : $override_currency;
//-eof-20151015-lat9-Enable cart->order processing to be cognizant of the order's currency *** 1 of 3 ***
in function cart()
Code:
$decimals = $currencies->get_decimal_places(/*$_SESSION['currency']*/ $this->currency); //-20151015-lat9-Enable cart->order processing to be cognizant of the order's currency *** 2 of 3 ***
Code:
$this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
//-bof-20151015-lat9-Enable cart->order processing to be cognizant of the order's currency *** 3 of 3 ***
'currency' => /*$_SESSION['currency']*/ $this->currency,
'currency_value' => $currencies->currencies[/*$_SESSION['currency']*/ $this->currency]['value'],
//-bof-20151015-lat9-Enable cart->order processing to be cognizant of the order's currency *** 3 of 3 ***
'payment_method' => $GLOBALS[$class]->title,
'payment_module_code' => $GLOBALS[$class]->code,
'coupon_code' => $coupon_code->fields['coupon_code'],
// 'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''),
// 'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''),
// 'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''),
// 'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''),
// 'cc_cvv' => (isset($GLOBALS['cc_cvv']) ? $GLOBALS['cc_cvv'] : ''),
'shipping_method' => (isset($_SESSION['shipping']['title'])) ? $_SESSION['shipping']['title'] : '',
'shipping_module_code' => (isset($_SESSION['shipping']['id']) && strpos($_SESSION['shipping']['id'], '_') > 0 ? $_SESSION['shipping']['id'] : $_SESSION['shipping']),
//-bof-20151015-lat9-Correct rounding error, using precision dictated by selected currency *** 1 of 4 ***
'shipping_cost' => $currencies->value (isset($_SESSION['shipping']['cost']) ? $_SESSION['shipping']['cost'] : 0, false, $this->currency),
//-eof-20151015-lat9-Correct rounding error, using precision dictated by selected currency *** 1 of 4 ***
'subtotal' => 0,
'shipping_tax' => 0,
'tax' => 0,
'total' => 0,
'tax_groups' => array(),
'comments' => (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''),
'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']
);
Code:
/*********************************************
* Calculate taxes for this product
*********************************************/
//-bof-20151015-lat9-Correct rounding error, using precision dictated by selected currency *** 2 of 4 ***
$shown_price = $currencies->value (zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']), false, $this->currency)
+ $currencies->value (zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']), false, $this->currency);
//-eof-20151015-lat9-Correct rounding error, using precision dictated by selected currency *** 2 of 4 ***
$this->info['subtotal'] += $shown_price;
$this->notify('NOTIFIY_ORDER_CART_SUBTOTAL_CALCULATE', array('shown_price'=>$shown_price));
// find product's tax rate and description
$products_tax = $this->products[$index]['tax'];
$products_tax_description = $this->products[$index]['tax_description'];
if (DISPLAY_PRICE_WITH_TAX == 'true') {
// calculate the amount of tax "inc"luded in price (used if tax-in pricing is enabled)
$tax_add = $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)));
} else {
// calculate the amount of tax for this product (assuming tax is NOT included in the price)
// $tax_add = zen_round(($products_tax / 100) * $shown_price, $currencies->currencies[$this->info['currency']]['decimal_places']);
$tax_add = ($products_tax/100) * $shown_price;
}
//-bof-20151015-lat9-Correct rounding error, using precision dictated by selected currency *** 3 of 4 ***
$tax_add = $currencies->value ($tax_add, false, $this->currency);
//-eof-20151015-lat9-Correct rounding error, using precision dictated by selected currency *** 3 of 4 ***
$this->info['tax'] += $tax_add;
foreach ($taxRates as $taxDescription=>$taxRate)
{
//-bof-20151015-lat9-Correct rounding error, using precision dictated by selected currency *** 4 of 4 ***
$taxAdd = $currencies->value (zen_calculate_tax($this->products[$index]['final_price']*$this->products[$index]['qty'], $taxRate), false, $this->currency)
+ $currencies->value (zen_calculate_tax($this->products[$index]['onetime_charges'], $taxRate), false, $this->currency);
//-eof-20151015-lat9-Correct rounding error, using precision dictated by selected currency *** 4 of 4 ***
if (isset($this->info['tax_groups'][$taxDescription]))
{
$this->info['tax_groups'][$taxDescription] += $taxAdd;
} else
{
$this->info['tax_groups'][$taxDescription] = $taxAdd;
}
}
/*********************************************
* END: Calculate taxes for this product
*********************************************/
and, finally, /includes/modules/payment/paypalwpp.php:
Code:
function ec_step1() {
global $order, $order_totals, $db, $doPayPal;
// if cart is empty due to timeout on login or shopping cart page, go to timeout screen
if ($_SESSION['cart']->count_contents() == 0) {
$message = 'Logging out due to empty shopping cart. Is session started properly? ... ' . "\nSESSION Details:\n" . print_r($_SESSION, TRUE) . 'GET:' . "\n" . print_r($_GET, TRUE);
include_once(DIR_WS_MODULES . 'payment/paypal/paypal_functions.php');
ipn_debug_email($message);
zen_redirect(zen_href_link(FILENAME_TIME_OUT, '', 'SSL'));
}
// init new order object
require(DIR_WS_CLASSES . 'order.php');
//-bof-20151015-lat9-Force order to be calculated in the precision dictated by the selected currency *** 1 of 1 ***
$order = new order ('', $this->selectCurrency ());
//-bof-20151015-lat9-Force order to be calculated in the precision dictated by the selected currency *** 1 of 1 ***
Bookmarks