So here are the changes I recommend to support the inc/excl VAT module.
First, update the includes/functions/extra_functions/inc_ex_functions.php file to change this:
Code:
if ($product_check->fields['product_is_free']=='1')
$show_normal_price='<s>'.display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])).'</s>';
else
$show_normal_price=display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id']));
Around line 112 to this (in red):
Code:
if ($product_check->fields['product_is_free']=='1')
$show_normal_price='<s>'.display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])).'</s>';
else
$show_normal_price='<span class="normalprice">'.display_price($display_normal_price, zen_get_tax_rate($product_check->fields['products_tax_class_id'])).'</span>';
Then in includes/modules/pages/product_info/jscript_dynamic_price_updater.php:
At and around line 222:
Code:
for (var a=0,b=test.length; a<b; a++) {
if (test[a].className == "productSpecialPrice" || test[a].className == "productSalePrice" || test[a].className == "productSpecialPriceSale") {
psp = test[a];
}
}
Add: a check for the className normalprice and a check for the "alternate tax" display possibilities:
Code:
var pspInclEx = false;
var pspEx = false;
var pspIncl = false;
for (var a=0,b=test.length; a<b; a++) {
if (test[a].className == "normalprice" || test[a].className == "productSpecialPrice" || test[a].className == "productSalePrice" || test[a].className == "productSpecialPriceSale") {
psp = test[a];
}
}
if (test[a].className == "productIncExTaxPrice") {
pspInclEx = test[a];
}
if (test[a].className == "productTaxExPrice") {
pspEx = test[a];
}
if (test[a].className == "productTaxPrice") {
pspIncl = test[a];
}
Then below that beginning at line 243:
Code:
switch (type) {<?php // the 'type' attribute defines what type of information is being provided ?>
case "priceTotal":
if (psp) {
psp.innerHTML = temp[i].childNodes[0].nodeValue;
} else {
thePrice.innerHTML = temp[i].childNodes[0].nodeValue;
}
if (_secondPrice !== false) {
this.updSP();
}
break;
case "quantity":
with (temp[i].childNodes[0]) {
if (nodeValue != "") {
if (psp) {
psp.innerHTML += nodeValue;
} else {
thePrice.innerHTML += nodeValue;
}
this.updSP();
}
}
break;
Insert additional cases of "priceTotalInclTax", "priceTotalExcTax", and "priceTotalIncExcTax" to support the various classes that the plugin uses.
Code:
switch (type) {<?php // the 'type' attribute defines what type of information is being provided ?>
case "priceTotal":
if (psp) {
psp.innerHTML = temp[i].childNodes[0].nodeValue;
} else {
thePrice.innerHTML = temp[i].childNodes[0].nodeValue;
}
if (_secondPrice !== false) {
this.updSP();
}
break;
case "priceTotalInclTax":
if (pspIncl) {
pspIncl.innerHTML = temp[i].childNodes[0].nodeValue;
}
break;
case "priceTotalExcTax":
if (pspEx) {
pspEx.innerHTML = temp[i].childNodes[0].nodeValue;
}
break;
case "priceTotalInclExcTax":
if (pspInclEx) {
pspInclEx.innerHTML = temp[i].childNodes[0].nodeValue;
}
break;
case "quantity":
with (temp[i].childNodes[0]) {
if (nodeValue != "") {
if (psp) {
psp.innerHTML += nodeValue;
} else {
thePrice.innerHTML += nodeValue;
}
this.updSP();
}
}
break;
Then in includes/classes/dynamic_price_updater.php within the prepareOutput function modifying (for now) the area in blue below (a similar modification will be incorporated for when not showing the currency symbols, but first am trying to get through with when they are displayed):
Code:
if (DPU_SHOW_CURRENCY_SYMBOLS == 'false') {
$decimal_places = $currencies->get_decimal_places($_SESSION['currency']);
$this->responseText['priceTotal'] .= number_format($this->shoppingCart->total, $decimal_places);
} else {
$this->responseText['priceTotal'] .= $currencies->display_price($this->shoppingCart->total, zen_get_tax_rate($product_check->fields['products_tax_class_id'])/* 0 */ /* DISPLAY_PRICE_WITH_TAX */);
}
Incorporate the following (in red, the "blue" line remains unchanged):
Code:
if (DPU_SHOW_CURRENCY_SYMBOLS == 'false') {
$decimal_places = $currencies->get_decimal_places($_SESSION['currency']);
$this->responseText['priceTotal'] .= number_format($this->shoppingCart->total, $decimal_places);
} else {
$product_tax_class_id = zen_products_lookup((int)$_POST['products_id'], 'products_tax_class_id');
$tax_rate = zen_get_tax_rate($product_tax_class_id); // Rate comes back as a "whole number" such as 20% returns 20 and NOT 0.20
if (DISPLAY_PRICE_WITH_TAX != 'false') {
$price_without_tax = 100.0 * $this->shoppingCart->total / ($tax_rate + 100.0); // Price of product without tax
$this->responseText['priceTotalInclExcTax'] = $this->responseText['priceTotal'] . $currencies->display_price($price_without_tax, 0);
$this->responseText['priceTotalExcTax'] = $currencies->display_price($price_without_tax, 0);
} else {
$this->responseText['priceTotalInclExcTax'] = $this->responseText['priceTotal'] . $currencies->display_price($this->shoppingCart->total + zen_calculate_tax($this->shoppingCart->total, $tax_rate), 0);
$this->responseText['priceTotalInclTax'] = $currencies->display_price($this->shoppingCart->total + zen_calculate_tax($this->shoppingCart->total , $tax_rate), 0);
}
$this->responseText['priceTotal'] .= $currencies->display_price($this->shoppingCart->total, 0)/* 0 */ /* DISPLAY_PRICE_WITH_TAX */;
}
I may add a "switch" to the jscript file to detect if the incl/exc VAT plugin is installed/enabled/active, but need to identify what would trigger that "knowledge". Otherwise, for non-users of that code, additional javascript is sent to a browser and possibly a little processing speed/time by calculating the opposite price of what the store is showing on page load/attribute change with no other ill effect(s) by this change.
Bookmarks