close ad
Help us test the new Databridge BETA with MySQLi support
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Problem refreshing <div class="addToCart"> in Products_Detail.php

Thread began 1/20/2010 6:10 am by davas56386677 | Last modified 2/17/2010 8:33 pm by davas56386677 | 2576 views | 14 replies

davas56386677

Here my solution and additional question

Hi Jason,

In order to display the price in EUR (right side) in Products_Detail.php when selecting either options or values, I had to add a function handling separators in "thePriceField" within the script. Look below (the whole script with modified code for "thePriceField" and added function "addSeparatorsNF(nStr, inD, outD, sep)":

<script>
function updateProduct(ProdID) {
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
return false;
}
}
}
var theForm = document.getElementById("WA_Store_Cart_1_ATC_<?php echo $row_WADAProducts["ProductID"]; ?>");
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
if (xmlHttp.responseText != "") {
var theRet=xmlHttp.responseText;
var thePriceField = getFromRSDump(theRet,"ProductPrice");
if (thePriceField.indexOf(".")==-1) {
thePriceField += ".00";
thePriceField = addSeparatorsNF(thePriceField, '.', ',', '.');
thePriceField = thePriceField += " €";
}
if (thePriceField.indexOf(".")==thePriceField.length-2) {
thePriceField += "0";
thePriceField = addSeparatorsNF(thePriceField, '.', ',', '.');
thePriceField = thePriceField += " €";
}
document.getElementById("ProductPrice").innerHTML = thePriceField;
document.getElementById("WADAPageTitle").innerHTML = getFromRSDump(theRet,"ProductName");
document.getElementById("ProductCartDesc").innerHTML = getFromRSDump(theRet,"ProductName");
document.getElementById("ProductLongDesc").innerHTML = getFromRSDump(theRet,"ProductLongDesc");
//document.getElementById("ProductShortDesc").innerHTML = getFromRSDump(theRet,"ProductShortDesc");
document.getElementById("ProductImage").src = "Images/Upload/" + getFromRSDump(theRet,"ProductImage");
document.getElementById("WA_Store_Cart_1_ID_Add").value = getFromRSDump(theRet,"ProductID");
theForm.action = theForm.action.replace(/ProductID=\d*/,"ProductID="+getFromRSDump(theRet,"ProductID"));
document.getElementById("checkingAvail").style.display="none";

if ((parseFloat(getFromRSDump(theRet,"NumLeft")) > 0 || parseInt(getFromRSDump(theRet,"ProductUnlimited")) != 0) && parseInt(getFromRSDump(theRet,"ProductLive")) != 0) {
document.getElementById("addFields").style.display="block";
}
if (parseInt(getFromRSDump(theRet,"ProductLive")) == 0) {
document.getElementById("notSold").style.display="block";
}
if (parseFloat(getFromRSDump(theRet,"NumLeft")) <= 0 && parseInt(getFromRSDump(theRet,"ProductLive")) != 0 && parseInt(getFromRSDump(theRet,"ProductUnlimited")) == 0) {
document.getElementById("soldOut").style.display="block";
}

var numOptions = 0;

numOptions = theRet.match(/\['options'\]=>([^\r\n]*)/);
if (parseInt(numOptions[1]) > 0) {

updateOptions(theRet.substring(theRet.indexOf(numOptions[0])+numOptions[0].length));

}
}
for (var x=0; x<theForm.elements.length; x++) {
theForm.elements.item([x]).removeAttribute("disabled");
}
}
}
var thepage = "Products_Detail_Lookup.php?ProductID="+ProdID;

xmlHttp.open("GET",thepage,true);
xmlHttp.send(null);
document.getElementById("addFields").style.display="none";
document.getElementById("notSold").style.display="none";
document.getElementById("soldOut").style.display="none";
document.getElementById("checkingAvail").style.display="block";
for (var x=0; x<theForm.elements.length; x++) {
theForm.elements.item([x]).disabled="disabled";
}
}

function updateOptions(theOptions) {
var theNameMatch = theOptions.match(/\['name'\]=>([^\r\n]*)/);
while (theNameMatch) {
theOptions = theOptions.substring(theOptions.indexOf(theNameMatch[0]) + theNameMatch[0].length);
nextName = theOptions.match(/\['name'\]=>([^\r\n]*)/);
nextIndex = theOptions.length;
if (nextName) {
nextIndex = theOptions.indexOf(nextName[0]);
}
nextValue = theOptions.match(/\['value'\]=>([^\r\n]*)/);
x = 0;
while (nextValue && theOptions.indexOf(nextValue[0]) < nextIndex) {
document.getElementById(theNameMatch[1].replace(/[\n\r\t]/g,"")).options[x].value = nextValue[1];
nextIndex-=theOptions.indexOf(nextValue[0]) + nextValue[0].length;
theOptions = theOptions.substring(theOptions.indexOf(nextValue[0]) + nextValue[0].length);
nextValue = theOptions.match(/\['value'\]=>([^\r\n]*)/);
x++;
}
theNameMatch = theOptions.match(/\['name'\]=>([^\r\n]*)/);
}
}

function getFromRSDump(RSDump,colName) {
var theReg = new RegExp('\\s\\["'+colName+'"\\]=>\\s([\\w\\W]*)');
var theMatch = RSDump.match(theReg);
var theRet = "";
if (theMatch) {
var nextMatch = theMatch[1].search(/\s\["[^\r\n]*"\]=>/);
if (nextMatch > 0) {
theMatch[1] = theMatch[1].substring(0,nextMatch);
}
theRet = theMatch[1].substring(theMatch[1].indexOf('"')+1,theMatch[1].lastIndexOf('"'));
}
return theRet;
}

function addSeparatorsNF(nStr, inD, outD, sep)
{
nStr += '';
var dpos = nStr.indexOf(inD);
var nStrEnd = '';
if (dpos != -1) {
nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
nStr = nStr.substring(0, dpos);
}
var rgx = /(\d+)(\d{3})/;
while (rgx.test(nStr)) {
nStr = nStr.replace(rgx, '$1' + sep + '$2');
}
return nStr + nStrEnd;
}

</script>

This modified script within Products_Detail.php may be of interest to everybody who needs to display the price like "12.345,67 €". Those who need another currency symbol have just to modify the line "thePriceField = thePriceField += " €"; replacing the € symbol with whatever needed.


Just a little question: in DYNAMICWEBCHART used in Powerstore 2 for instance in Products_Chart_Results_Data1.php the french accented characters contained in ProductName (or similar) to fill #key# in <![CDATA[Pour: #x_label#<br>#key#<br>Unit%c3%a9(s) vendue(s): #val# ]]> are displayed as an é instead of an é. This happened since I made the fresh install of Powerstore using your MySQL configuration.
Remember: I changed all charset=ISO-8859-1 to charset=UTF-8 to comply the closest possible to the original Powerstore 2 (out of the box). The only charsets left to ISO-8859-1 are those within the PHP files that handle the data for the charts (in the \data subdirectory). When changing these particular chasets to UTF-8, the chart stops building up and displays only vertical lines (the tooltip shows: undefined).

<point datagroup="Total">
<label><?php echo($start); ?></label>
<value><?php echo($total); ?></value>
<tooltip>
<![CDATA[Pour: #x_label#<br>#key#<br>Unit%c3%a9(s) vendue(s): #val# ]]>
</tooltip>
<pointlink>Products_Chart_Daily.php?month=<?php echo($month); ?>%26year=<?php echo($year); ?>%26ProductSKU=<?php echo($sku); ?></pointlink>
</point>

Keep in mind that when using charset=ISO-8859-1 throughout the complete Powerstore 2 package and MySQL configured with utf8_general_ci (or utf8_unicode_ci) then the é are stored as é within the database field and displays also correctly (as é) in the chart, thus avoidind the troubles encountered now.

So to me it seems that there must be a trick (encoding - decoding feature) to foul the chart builder so that he translates the é (actual configuration of the fresh install as told by you in previous post) into é. A similar problem occurs in the receipt.php (WA_Universal_Email\Email_Templates), where the
<?php echo $WA_Store_Cart->DisplayInfo("Name"); ?> displays as Société instead of Société within the confirmation email the customer receives.

Ask the team to check this in depth and help me to find where in the complete Powerstore 2 code a explicit encoding - decoding is used to configure the output (email and chart side)

Many thanks for your assistance

Dan

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...