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

Dynamic Price Updater

Views: 342,266

Results 1,501 to 1,520 of 1,701
14 Jan 2019, 9:51 AM
#1501
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Dynamic Price Updater

mc12345678:

Have you incorporated the applicable jscript_framework.js file(s) into your template?

Aha! Well thought, yes the framwork file was missing from my older style template files, added this in and spinning wheel now gives a price.
But this price remains the same, no matter what attributes are chosen..

14 Jan 2019, 12:27 PM
#1502
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Dynamic Price Updater

Calljj:

Aha! Well thought, yes the framwork file was missing from my older style template files, added this in and spinning wheel now gives a price.
But this price remains the same, no matter what attributes are chosen..
Looks like some troubleshooting is necessary. Would suggest first seeing what if anything is logged in the console (F12 and then review what is essentially a debug screen or often called a console). Then assuming that the jscript_ file for the product type in question is up-to-date, would set a breakpoint in the javascript (shown to have loaded because of the issues involved), modify a an attribute selection and follow the javascript to see that it goes to completion. As part of that at least looking at the results to be presented to the page. If see that new text is to be provided, but it isn't updated, to then verify that the html object(s) to be updated are in the page's source code.
The next thing to think of is the settings for the applicable attributes as to include the price(s) in the pricing. This could be done at any point in the above checks.

17 Jan 2019, 11:22 AM
#1503
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

mc12345678:

Looks like some troubleshooting is necessary. Would suggest first seeing what if anything is logged in the console (F12 and then review what is essentially a debug screen or often called a console). Then assuming that the jscript_ file for the product type in question is up-to-date, would set a breakpoint in the javascript (shown to have loaded because of the issues involved), modify a an attribute selection and follow the javascript to see that it goes to completion. As part of that at least looking at the results to be presented to the page. If see that new text is to be provided, but it isn't updated, to then verify that the html object(s) to be updated are in the page's source code.
The next thing to think of is the settings for the applicable attributes as to include the price(s) in the pricing. This could be done at any point in the above checks.

So the response given in the console is changing every time i make a change in atttribute selection...

responseText: "\r\n\ufeff{\"responseType\":\"success\",\"data\":{\"priceTotal\":\"<font size=\\\"0.5\\\" color=\\\"#636363\\\">Price: <\\/font>£1,459.00\",\"preDiscPriceTotalText\":\"<font size=\\\"0.5\\\" color=\\\"#636363\\\">Price: <\\/font>\",\"preDiscPriceTotal\":\"£1,215.83\",\"stock_quantity\":\"1\",\"weight\":\"7\"}}"
responseText: "\r\n\ufeff{\"responseType\":\"success\",\"data\":{\"priceTotal\":\"<font size=\\\"0.5\\\" color=\\\"#636363\\\">Price: <\\/font>£1,209.00\",\"preDiscPriceTotalText\":\"<font size=\\\"0.5\\\" color=\\\"#636363\\\">Price: <\\/font>\",\"preDiscPriceTotal\":\"£1,007.50\",\"stock_quantity\":\"1\",\"weight\":\"7\"}}"

and the area on the page productPrices is displayed in is refreshing... i.e spinning wheel and then displaying a price... its just that it's still the original price. so not showing the changes given in the response...

17 Jan 2019, 11:53 AM
#1504
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Dynamic Price Updater

Calljj:

So the response given in the console is changing every time i make a change in atttribute selection...

responseText: "\r\n\ufeff{"responseType":"success","data":{"priceTotal":"<font size=\"0.5\" color=\"#636363\">Price: <\/font>£1,459.00","preDiscPriceTotalText":"<font size=\"0.5\" color=\"#636363\">Price: <\/font>","preDiscPriceTotal":"£1,215.83","stock_quantity":"1","weight":"7"}}"

> 
> ```
responseText: "\r\n\ufeff{\"responseType\":\"success\",\"data\":{\"priceTotal\":\"<font size=\\\"0.5\\\" color=\\\"#636363\\\">Price: <\\/font>£1,209.00\",\"preDiscPriceTotalText\":\"<font size=\\\"0.5\\\" color=\\\"#636363\\\">Price: <\\/font>\",\"preDiscPriceTotal\":\"£1,007.50\",\"stock_quantity\":\"1\",\"weight\":\"7\"}}"

and the area on the page productPrices is displayed in is refreshing... i.e spinning wheel and then displaying a price... its just that it's still the original price. so not showing the changes given in the response...
From my perspective, that's good that the results "expected" are being fed back. It's that the location for them to land at doesn't match something. Can you take a look at the page's source code and provide the html surrounding the price box?

17 Jan 2019, 12:37 PM
#1505
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

ok, seems to fail within the jscript_dynamic_price_updater.php
when approx line 139, makes a call to

zcJS.ajax(option).done{

which my result goes to

.fail( function(jqXHR,textStatus,errorThrown) {
17 Jan 2019, 12:40 PM
#1506
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

Changing code to

.fail( function(jqXHR,textStatus,errorThrown) {
            alert(errorThrown);

gives:

SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data

17 Jan 2019, 1:04 PM
#1507
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

Calljj:

Changing code to

.fail( function(jqXHR,textStatus,errorThrown) {
alert(errorThrown);

> 
> gives:
> 
> SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data

then showing the JSON gives:

{"XML":"securityToken=468ca6253914efa9633b14fdd8368a21&id[1]=2&id[2]=97&id[32]=292&cart_quantity=1&products_id=8902&pspClass=productGeneral&stat=main&outputType=XML","JSON":{"securityToken":"468ca6253914efa9633b14fdd8368a21","id[1]":"2","id[2]":"97","id[32]":"292","cart_quantity":"1","products_id":"8902","pspClass":"productGeneral","stat":"main","outputType":"JSON"}}

17 Jan 2019, 2:05 PM
#1508
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Dynamic Price Updater

Calljj:

then showing the JSON gives:

{"XML":"securityToken=468ca6253914efa9633b14fdd8368a21&id[1]=2&id[2]=97&id[32]=292&cart_quantity=1&products_id=8902&pspClass=productGeneral&stat=main&outputType=XML","JSON":{"securityToken":"468ca6253914efa9633b14fdd8368a21","id[1]":"2","id[2]":"97","id[32]":"292","cart_quantity":"1","products_id":"8902","pspClass":"productGeneral","stat":"main","outputType":"JSON"}}


Something doesn't look right about that returned "JSON", if the includes/classes/dynamic_price_updater.php file of the current version were in place then only either XML **OR** JSON would be returned not both.

Here is the JSON response I get when using firefox on ZC default demo product index.php?main_page=product_info&cPath=54_56&products_id=159:

{"responseType":"success","data":{"sideboxContent":"<span class="DPUSideBoxName">Base price</span><span class="DPUSideboxQuantity"> x 0</span> ($33.00)<br /><span class="DPUSideBoxName">Yellow</span><span class="DPUSideboxQuantity"> x 1</span> ($0.00)<br /><hr /><span class="DPUSideboxTotalText">Total: </span><span class="DPUSideboxTotalDisplay">$33.00</span>","priceTotal":"Sale: $33.00","preDiscPriceTotalText":"Sale: ","midDiscPriceTotal":"$35.50","preDiscPriceTotal":"$35.50","stock_quantity":"10000","weight":"1"}}


Now there is a little extra data sent back as I am trying to work on the "middle" price display for a product that would display three different prices if has say a special and a sale.
17 Jan 2019, 2:10 PM
#1509
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Dynamic Price Updater

This is the function in question at the end of the file:

  /*
   * Formats the response and flushes with the appropriate headers
   * This should be called last as it issues an exit
   *
   * @return void
   */
  protected function dumpOutput($outputType = "XML") {
    if ($outputType == "XML") {
    // output the header for XML
    header("content-type: text/xml");
    // set the XML file DOCTYPE
    echo '<?xml version="1.0" encoding="UTF-8" ?>' . "\n";
    // set the responseType
    echo '<root>' . "\n" . '<responseType>' . $this->responseType . '</responseType>' . "\n";
    // now loop through the responseText nodes
    foreach ($this->responseText as $key => $val) {
      echo '<responseText' . (!is_numeric($key) && !empty($key) ? ' type="' . $key . '"' : '') . '><![CDATA[' . $val . ']]></responseText>' . "\n";
    }
    die('</root>');
    } elseif ($outputType == "JSON") {
      $data = array();
      // output the header for JSON
      header('Content-Type: application/json');
      // DO NOT set a JSON file DOCTYPE as there is none to be included.
//      echo '<?xml version="1.0" encoding="UTF-8" ' . "\n";
      // set the responseType
      $data['responseType'] = $this->responseType;
      // now loop through the responseText nodes
      foreach ($this->responseText as $key => $val) {
          if (!is_numeric($key) && !empty($key)) {
            $data['data'][$key] = $val;
          }
      }
      die(json_encode($data));
    }
  }

$data is an array that is created in the function, $this->responseText is populated throughout the class, but it contains only the key/response information captured throughout the process and XML is not at all captured in that process from what I see of the file. The die at the end of each if statement is present to prevent processing any further information.

Is an older version or mix of files being used for some reason?

17 Jan 2019, 2:16 PM
#1510
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

nope, all latest, the json i presented was the request to the ajax, not the response, i presumed it was getting the hump with the request seeing as the result was an error.
i posted the response back earlier in the thread:

pasted here again for clarity:

responseText: "\r\n\ufeff{\"responseType\":\"success\",\"data\":{\"priceTotal\":\"<font size=\\\"0.5\\\" color=\\\"#636363\\\">Price: <\\/font>£1,209.00\",\"preDiscPriceTotalText\":\"<font size=\\\"0.5\\\" color=\\\"#636363\\\">Price: <\\/font>\",\"preDiscPriceTotal\":\"£1,007.50\",\"stock_quantity\":\"1\",\"weight\":\"7\"}}"
17 Jan 2019, 2:20 PM
#1511
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Dynamic Price Updater

Calljj:

nope, all latest, the json i presented was the request to the ajax, not the response, i presumed it was getting the hump with the request seeing as the result was an error
I'm currently away from a device that can show me related information. Will respond back when able. Note, that between now and then, if this site is not navigated, you will not receive notification of my response if you only read your emails.

17 Jan 2019, 2:22 PM
#1512
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

mc12345678:

This is the function in question at the end of the file:

$data is an array that is created in the function, $this->responseText is populated throughout the class, but it contains only the key/response information captured throughout the process and XML is not at all captured in that process from what I see of the file. The die at the end of each if statement is present to prevent processing any further information.

outputs:

 Array
(
    [responseType] => success
    [data] => Array
        (
            [priceTotal] => <font size="0.5" color="#636363">Price: </font>£909.00
            [preDiscPriceTotalText] => <font size="0.5" color="#636363">Price: </font>
            [preDiscPriceTotal] => £757.50
            [stock_quantity] => 1
            [weight] => 7
        )

)
17 Jan 2019, 5:17 PM
#1513
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Dynamic Price Updater

Calljj:

outputs:

Array
(
[responseType] => success
[data] => Array
(
[priceTotal] => <font size="0.5" color="#636363">Price: </font>£909.00
[preDiscPriceTotalText] => <font size="0.5" color="#636363">Price: </font>
[preDiscPriceTotal] => £757.50
[stock_quantity] => 1
[weight] => 7
)

)


Would you mind trying something?

file: includes/modules/pages/product_info/jscript_dynamic_price_updater.php
Line: 137

Change: 

_this.responseJSON = jqXHR.responseJSON;

to:

_this.responseJSON = response;


Also, could you in the watch screen enter the following and identify what version of software we are talking about?

jQuery.fn.jquery

18 Jan 2019, 9:10 AM
#1514
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

mc12345678:

Would you mind trying something?

file: includes/modules/pages/product_info/jscript_dynamic_price_updater.php
Line: 137

Change:

_this.responseJSON = jqXHR.responseJSON;

> to:
> ```
_this.responseJSON = response;

Also, could you in the watch screen enter the following and identify what version of software we are talking about?

jQuery.fn.jquery


so changing the line not made any difference, the error is thrown back as a result of the request, whereas that line is processing a successfull request?

jquery gives 3.2.1

thanks for continued help on this.
18 Jan 2019, 11:26 AM
#1515
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Dynamic Price Updater

Calljj:

so changing the line not made any difference, the error is thrown back as a result of the request, whereas that line is processing a successfull request?

jquery gives 3.2.1

thanks for continued help on this.

That seem to indicate that for some reason returning from the class back to the page, the data is basically being stripped...

By making that change, the variable _this.responseJSON was supposed to be set to the response data, the if statement is intended to offer an alternate way of processing as has/had been identified maybe possible; however, now the responseText seems to not be formatted within the parse call to support making that conversion. So need to see what can be done/altered for that.

Can you also provide the value of responseText as identified just before that error? I'm going to try to see what I can offer as a modified suggestion, but I'm also wondering if some other header information needs to be sent from the class to prevent "screening" the data away.

18 Jan 2019, 11:49 AM
#1516
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Dynamic Price Updater

Calljj:

so changing the line not made any difference, the error is thrown back as a result of the request, whereas that line is processing a successfull request?

jquery gives 3.2.1

thanks for continued help on this.

Could you try:
in includes/classes/dynamic_price_updater.php
at/around line 746
just below:

      // output the header for JSON
      header('Content-Type: application/json');

adding:

      header('X-Content-Type-Options: nosniff');

so that area of the code would look like:

      // output the header for JSON
      header('Content-Type: application/json');
      header('X-Content-Type-Options: nosniff');

By the way is this happening on one browser only or any?

18 Jan 2019, 1:29 PM
#1517
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

mc12345678:

Could you try:
so that area of the code would look like:

  // output the header for JSON
  header('Content-Type: application/json');
  header('X-Content-Type-Options: nosniff');
> By the way is this happening on one browser only or any?

Changed code,no difference.
happening on all browsers.
18 Jan 2019, 4:01 PM
#1518
mc12345678 avatar

mc12345678

Totally Zenned

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

Re: Dynamic Price Updater

Calljj:

Changed code,no difference.
happening on all browsers.

Done a little more leg work... Looks like there might be an extra "blank" line somewhere in the process.

Check the following file to ensure that before the first <?php that there is no "hidden" character or return. If necessary delete the entire first line and retype the text of that line using your favorite plain text editor. Or should be able to copy the file from the latest distribution or from github.

includes/classes/ajax/zcDPU_Ajax.php

Also be sure that there is no closing ?> in the files. Having such a closing followed by a return could cause the same issue.

Further, I highly suspect the includes/classes/ajax/zcDPU_Ajax.php file as having from a while back the UTF8 BOM (Byte Order Mark) "character" that was accidentally added in when I was working on various filetypes some time ago. The file may look the same as the current version, but it is not and it will cause the problem described. I'll try to see if there is anything there in the current fileset, but if installation was done by comparison, then that character may have been missed. It is not a visible character like the text on this screen, but it would provide the opening content of the responseText where it shows: \r\n\ufeff

Once the responseText is "parsed" it turns that section into a carriage returned new line with the BOM character being the first character on the second line that is causing the issue.

Whatever method you use, could you please explain what was tried, what worked, and what didn't? I know someone else was having a somewhat similar problem, but it hadn't dawned on me as much about what was going on.

19 Jan 2019, 11:54 AM
#1519
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

mc12345678:

Further, I highly suspect the includes/classes/ajax/zcDPU_Ajax.php file as having from a while back the UTF8 BOM (Byte Order Mark) "character" that was accidentally added in when I was working on various filetypes some time ago.

So problem finally solved!
I would never have even thought of looking at the encoding issues of a file, the first time i've come across such an issue!
Indeed, it was not a character that was the issue, but the entire includes/classes/ajax/zcDPU_Ajax.php file being encoded in UTF8-BOM.
I opened the file in notepad++, changed the encoding to standard UTF8 and saved, and worked instantly!
Thank you again for your patience.

19 Jan 2019, 12:34 PM
#1520
calljj avatar

calljj

Zen Follower

Join Date:
Mar 2007
Posts:
253
Plugin Contributions:
2

Re: Dynamic Price Updater

OK, on to the next thing :D

sooo..... when a product is on sale, how do i get the "normalprice" to include the taxtation?
At the moment it gives:

Price: £649.17 £467.40
Save: 40% off