Now we dive into the actual script itself, lot of edits to make here.
In /my_skin/modules/Product_Options/func.js near line 21:
After:
PHP Code:
/**
* Rebuild page if some options is changed
*/
Replace:
PHP Code:
function check_options() {
With:
PHP Code:
function check_options(id) {
var product_price_id = 'product_price'+id;
Note: We are doing two things here, allowing input of the id variable that we set in our onchange event earlier, and setting a new variable, that just consists of the string "product_price" with the id tacked on the end. We'll use this to reference our span ID with the same unique name.
Next, near line 35:
After:
PHP Code:
if (typeof(taxes) != 'undefined') {
for (var t in taxes) {
if (hasOwnProperty(taxes, t))
local_taxes[t] = taxes[t][0];
}
}
Insert:
PHP Code:
if(typeof(id) != "undefined" && id !== null) {
price = eval("default_price" + id);
} else {
price = eval("default_price" + productid);
}
Note: This sets the price variable to the default_price again with the productid appended. The extra else statement is to prevent an error on the product page.
Next, near line 162:
After:
Replace:
PHP Code:
var _tmp = modi_price(price, local_taxes, orig_price);
With:
PHP Code:
var _tmp = modi_price(price, local_taxes, orig_price, id);
Note: We are passing on the id to the modi_price() function.
Next, near line 198:
After:
PHP Code:
/* Update form elements */
/* Update price */
Replace:
PHP Code:
if (document.getElementById('product_price'))
document.getElementById('product_price').innerHTML = price_format(Math.max(price, 0));
With:
PHP Code:
if (document.getElementById(product_price_id))
document.getElementById(product_price_id).innerHTML = price_format(Math.max(price, 0));
Note: Just referring to the span ID using the variable we set above.
Then, near line 315:
After:
PHP Code:
/**
* Calculate product price with price modificators
*/
Replace:
PHP Code:
function modi_price(_price, _taxes, _orig_price) {
var return_price = round(_price, 2);
With:
PHP Code:
function modi_price(_price, _taxes, _orig_price, id) {
var return_price = round(_price, 2);
if(typeof(id) != "undefined" && id !== null) {
var modifiers = eval("modifiers"+id);
} else {
var modifiers = eval("modifiers"+productid);
}
Note: Accepting the passed ID into the modi_price() function, and defining the modifiers variable. Again the else statement is to prevent an error when the variable is not set.
Well that's it! Hope it has been enlightening and entertaining. Remember this is just a quick little hack, it will not work in all instances, and there are certainly better ways to do this if you spent more time investigating it than I have. But it should get you started towards a more robust solution if that is your intention.
I have again uploaded the whole func.js file just in case I missed something. I renamed it to func.tpl so the forum would accept it.