Zen Cart Logo
Forums / All Other Contributions/Addons / Dynamic Price Updater

Dynamic Price Updater

Views: 342,334

Results 1,281 to 1,300 of 1,701
2 May 2017, 1:46 PM
#1281
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Dynamic Price Updater

I have also added the Dynamic Price Updater sidebox on teh right hand side, and the pricing here reads correctly.

2 May 2017, 2:59 PM
#1282
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Dynamic Price Updater

dharrison:

I have also added the Dynamic Price Updater sidebox on teh right hand side, and the pricing here reads correctly.
Looks like a perceived improvement was unnecessary...

The following should restore the operation:

in includes/classes/dynamic_price_updater.php
line 116, change:

 $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 */);

BACK To:

 $this->responseText['priceTotal'] .= $currencies->display_price($this->shoppingCart->total, 0/* 0 */ /* DISPLAY_PRICE_WITH_TAX */);

Deleting the additional tax calculation/determination. Seeing that the shopping cart class already determines the price based on tax included/excluded, there is no need to do a further calculation here.

This will be again incorporated back into the upcoming change that I have been preparing to use the ZC zcJS variable (when available), and to provide an improved installer so that issues like previously seen are less likely to occur. :)

Currently what is seen is that on page load a price is displayed, upon change of attribute (triggering the price adjustment), the displayed price becomes adjusted as if the displayed price needed to have the tax rate applied to it (again)... Thank you for your testing, the values and explanation of what was going wrong.

2 May 2017, 4:31 PM
#1283
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: Dynamic Price Updater

Yayyyy it works :clap:

I'm always glad to help on the very odd occasions that I do.

Thank you

2 May 2017, 4:50 PM
#1284
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Dynamic Price Updater

dharrison:

Yayyyy it works :clap:

I'm always glad to help on the very odd occasions that I do.

Thank you

I think what happened was that I was going to add more return data so that both the price with and price without tax could be returned as separate values and got sidetracked... Even trying to look at it now, it seems I would have to do a "reverse" calculation for cases where the store is set to display the price with tax and the without tax price was desired, because the function to "add" tax does not accept a negative number and at the point of return of data to the class, the shopping cart has already done all its math with the tax included in the final price and no "intermediate" or untaxed value is returned. I.e. other method is to do like what is done in the sidebox of running all of the numbers in the code. Prefer re-usability over maintaining additional/duplicate code, but... Alternatively the incl VAT/Excl VAT code includes some features for this, so could detect and reuse that code as necessary adding a potential dependency.

shaking head okay enough about that, thank you for noting the issue and providing the explanation(s). Once I had a "final" price, original price and an idea of what the VAT percentage was and looking at the code, it became quite obvious what was going on.

5 May 2017, 8:54 AM
#1285
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: Dynamic Price Updater

Hi is there a way to add a suffix after the price? Because we're displaying the price including & excluding VAT, we need to make sure that the customer knows the price is ex VAT

5 May 2017, 9:30 AM
#1286
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Dynamic Price Updater

dharrison:

Hi is there a way to add a suffix after the price? Because we're displaying the price including & excluding VAT, we need to make sure that the customer knows the price is ex VAT

There is, but seems to me that with the incl/exc VAT program installed that there are quite a few options available, things to set and a few modifications to make such as modifying the information to be displayed at the product info page to have/contain the suffix related to the price being displayed and that is contained in its own span.

Basically, the suffix (like the prefix) information (right or wrong) is located in the includes/classes/dynamic_price_updater.php file within the prepareOutput function. A suffix would logically follow after the assignment/line I suggested changing above.

5 May 2017, 10:10 AM
#1287
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: Dynamic Price Updater

Ok the updated price once an attribute is selected does not display whether the price is including or ex VAT. As we cater to both trade and customer, this makes a big difference (especially at 20%)

I see where to add the suffix, but (and yes I am a newbie when it comes to javascript) what do I add: I tried document.write() and this didn't work

Please help :)

5 May 2017, 10:36 AM
#1288
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: Dynamic Price Updater

Sorry I had a blonde moment. This is PHP :bangin:

But in my defence <?php echo ?> doesn't appear to work

5 May 2017, 11:00 AM
#1289
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Dynamic Price Updater

dharrison:

Ok the updated price once an attribute is selected does not display whether the price is including or ex VAT. As we cater to both trade and customer, this makes a big difference (especially at 20%)

I see where to add the suffix, but (and yes I am a newbie when it comes to javascript) what do I add: I tried document.write() and this didn't work

Please help :)

To be sure that we're going down the right path: on initial display of the price, the price value as well as a "suffix" are presented, correct? Isn't the price value in its own span class as compared to the suffix?

If so, it sounds like maybe the javascript portion is replacing "too much" text. I don't recall the class name even though I was adding functionality to the plugin yesterday to specifically address that plugin, but it includes text something like "...IncExc..." for the case where it is the "opposite" tax display, and a different class for the one that is the "normal" final display. If there are two spans displayed, one to show the price, one to show the text of what the price represents, then the file to change is in the includes/modules/pages/YOUR_PRODUCT_TYPE/ folder in the jscript_ file and the handlePrice function to capture the location to be updated as the variable psp.

If there is only one such class at the product price display then yes need to go back to the class file which is a php file not a javascript file. By that I mean, the responseText would be updated to append the suffix through standard php methods of appending text.

I believe you provided a link to one of your products, so will take a look soon and be able to further advise, but wanted to express what seemed to be expected as compared to what was asked.

5 May 2017, 11:13 AM
#1290
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Dynamic Price Updater

dharrison:

Sorry I had a blonde moment. This is PHP :bangin:

But in my defence <?php echo ?> doesn't appear to work
Welcome to AJAX. :) as stated in my last post, the suffix if added to the class file, would be appended to the responseText of the priceTotal key similar to the line modified in the correction posted before.

5 May 2017, 11:22 AM
#1291
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: Dynamic Price Updater

Yes just a suffix on the second price that reminds the visitor that the price given is "ex VAT"

5 May 2017, 11:47 AM
#1292
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Dynamic Price Updater

dharrison:

Yes just a suffix on the second price that reminds the visitor that the price given is "ex VAT"
I'll give my recommended code to add the suffix into the class file in a moment, but it appears that the inc_ex_functions file in includes/functions/extra_functions is missing a span tag in one place as seen by your website and then review of that code as downloaded a while back from zc. There is a line in that function file starting with

$show_normal_price=display_price(

The right side of that "equation" should be encompassed by a span of class normalPrice or similar it looks like.

5 May 2017, 12:10 PM
#1293
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: Dynamic Price Updater

On line 110? I have corrected that

5 May 2017, 1:15 PM
#1294
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Dynamic Price Updater

mc12345678:

I'll give my recommended code to add the suffix into the class file in a moment, but it appears that the inc_ex_functions file in includes/functions/extra_functions is missing a span tag in one place as seen by your website and then review of that code as downloaded a while back from zc. There is a line in that function file starting with

$show_normal_price=display_price(

> 
> The right side of that "equation" should be encompassed by a span of class normalPrice or similar it looks like.

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:
    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):
    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:

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:

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:
  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.
  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):
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):
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.
5 May 2017, 1:19 PM
#1295
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Dynamic Price Updater

dharrison:

On line 110? I have corrected that

If I am correct, line 10 didn't have a class assigned and just had a strike through <s>. Generally speaking, that is as expected because there would/should be some other class that follows and would be replaced with an applicable price to update. It would be two lines down where there is no "html" surrounding the price value(s). It appears to be causing on your product info page for the "base price" to not be uniquely surrounded by a span that can be "tagged" and therefore the entire content is being replaced not just the applicable price(s).

BTW, feedback on the above modification would be greatly appreciated as I have it staged (locally) to be posted to github and to ZC for incorporation. Would like to get it as close to fully operational as possible.

5 May 2017, 2:19 PM
#1296
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: Dynamic Price Updater

Hi

Ok will do.

6 May 2017, 5:00 PM
#1297
dharrison avatar

dharrison

Zen Follower

Join Date:
Mar 2009
Location:
Essex, UK
Posts:
448
Plugin Contributions:
0

Re: Dynamic Price Updater

Around line 112 to this (in red):

    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>';

I did this and as a result the including VAT price now has a strikethrough

Attachment 17049

> Then in includes/modules/pages/product_info/jscript_dynamic_price_updater.php:
> At and around line 222:
> ```
  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:

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:
> ```
      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.

  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;


This stopped the Price Updater working

> 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):
> ```
    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):

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.

The DPU doesn't work at the moment.  I have followed your instructions clearly twice now with the same result.
9 May 2017, 12:23 PM
#1298
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Dynamic Price Updater

mc12345678:

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:

    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):
> ```
        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:

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:
> ```
  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:

  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.
> ```
      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):

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):
> ```
    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.

dharrison:

I did this and as a result the including VAT price now has a strikethrough

Attachment 17049

This stopped the Price Updater working

The DPU doesn't work at the moment. I have followed your instructions clearly twice now with the same result.

It seems that there are other changes that have been made unrelated to the above suggestions to support continued display of both included and excluded taxes. Possibly something modified in the includes/classes/dynamic_price_updater.php file? Or more likely based on system response, the includes/configure.php file has been modified for this sub-directory store, because from the above link, clicking on anything there takes one to the "live" store instead of remaining in the temporary store.

I've "externally" checked what is presented at the provided link and while initially the page loads just fine, all of the links point to the main directory not to the "temporary" directory that appears to have been created. This then causes thing like the ajax to fail because it look like there is a cross browser type situation occurring. When the default sub-directory is removed, then the site loads, and as of just now, DPU is working as it originally was recently provided, but without edits suggested above being visible. So, it seems that the primary issue over the last few days related to the provided link is that it did not direct/redirect to a properly formed/generated site, therefore any other issues at that point were unrelated to DPU.

As to the line through with the normalprice class, yeah I can see how the use of that class is already designated to format with a line-through (the normalprice class is used when the normal price is displayed and some other price is present such as a special or a sale). Not using a class of some type in that area causes the overall price swap to fail/cause what is being seen of the entire "block" being replaced. Perhaps use of normalInclExcPrice as the class to be used to support swapping could work. That way at least the price is editable without a lot of text manipulation or substitution. It somewhat depends on what is desired/necessary. I have installed a version of the includes/excludes VAT price module and have been working on a solution that does not require an additional incl/exc VAT function with the current result being that on change of the attribute, both the included and excluded VAT price are shown, but the sale, special, etc.. price has been replaced as well thus far in testing. It would be nice to just replace the necessary values, which in part I have been able to do, but further ideally would be for this plugin to be provided to operate as normal without any subsequent changes and to also operate "as normal" with the incl/exc VAT plugin such that again no code changes to DPU would be necessary. It does look like though that the incl/exc VAT plugin could use a few tweaks to support being installed, to have the necessary switch adjustments to affect display, but to also be "disabled" without having to be removed. I believe countrycharm had at one point posted a slightly updated version, but even that could use a few modifications to accomplish the installed but not adding to the returned text.

9 May 2017, 6:49 PM
#1299
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Dynamic Price Updater

@dharrison - is just me or does the zenID also appear for you on every link?

To prevent that:

Admin -> Configuration -> Sessions
Cookie Domain
Force Cookie Use

  • make sure they both say True

Also, you have some links in the HTML HEADER using "http://" links instead of "https://" which is causing my Browser to give Warning msgs.

16 May 2017, 8:46 AM
#1300
webchills avatar

webchills

Zen Follower

Join Date:
Sep 2005
Location:
Austria
Posts:
99
Plugin Contributions:
1

Re: Dynamic Price Updater

I have noticed that the config setting DPU_SHOW_LOADING_IMAGE (true to show a small loading graphic so the user knows something is happening) is misleading as if you set it to false the whole functionality is not loading anymore. There is no image loading but no price change as well :-) If the graphic is needed it would be better to remove this setting. If the graphic is not needed something must be wrong in the ```

<?php if (DPU_SHOW_LOADING_IMAGE == 'true') { ?>