Hi guys and girls,
While doing a search on Google for something I came across a website that has some code on it that allows the price listed on your product page to change depending on what option you have selected. As shown on this website here.
http://store.passion4health.biz/inde...60-120%29.html
If you select one of the options from the drop down box you will notice that the price on the products page is updated automatically to include the option price that you selected.
Here is the code that is used to do this and on the page this code is mentioned the fellow has written the following:
*NB:* Please don't just cut and paste the code. You will need to play with the regex based on our option values.
So my question is. Does anyone know where this code is to be inserted and in to which file is it to be inserted to?Code:$j("document").ready(function(){ var newprice = parseFloat($our_price); var initialfinals = {}; $j('#attrib-1 option').each(function(option){ arr = $j(this).text().match(/(.*) \( ([+,-])\$(.*) \)$/); if (arr) { if (arr[2] == "+") { initialfinals[arr[1]] = parseFloat($our_price) + parseFloat(arr[3]); } else { initialfinals[arr[1]] = parseFloat($our_price) - parseFloat(arr[3]); } } else { initialfinals[$j(this).text()] = parseFloat($our_price); } }); $j('#attrib-1').change(function(){ arr = $j('#attrib-1 option:selected').text().match(/(.*) \( ([+,-])\$(.*) \)$/); if (arr) { var upgrade = arr[3]; newprice = parseFloat(initialfinals[arr[1]]); } $j('#our_price').html('Our Price: $'+newprice.toFixed(2)); //recalc other options.... $j('#attrib-1 option').each(function(option) { arr = $j(this).text().match(/([a-z,A-Z,0-9]* *[a-z,A-Z,0-9]*)[ ,\(]*/); delta = newprice - initialfinals[arr[1]] newoption = ""; if (delta > 0) { newoption = arr[1]+ " ( -$"+delta.toFixed(2)+" )"; } if (delta <0) { delta = -1 - (delta) +1; newoption = arr[1]+" ( +$"+delta.toFixed(2)+" )"; } if (delta == 0) { newoption = arr[1]; } $j(this).text(newoption); }); }); })
Also what is meant by the fellows comment when he says "You will need to play with the regex based on our option values." ? What is regex and where can it be found?
Any help on this would be very much appreciated as it looks like a great mod.
Thanks.


Reply With Quote
