View Single Post
  #17  
Old 06-28-2012, 03:26 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Product options in product list

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(taxest))
        
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:
PHP Code:
/* Find modifiers */ 
Replace:
PHP Code:
var _tmp modi_price(pricelocal_taxesorig_price); 
With:
PHP Code:
var _tmp modi_price(pricelocal_taxesorig_priceid); 
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(price0)); 
With:
PHP Code:
if (document.getElementById(product_price_id))
    
document.getElementById(product_price_id).innerHTML price_format(Math.max(price0)); 
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(_price2); 
With:
PHP Code:
function modi_price(_price_taxes_orig_priceid) {
  var 
return_price round(_price2);
  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.
Attached Files
File Type: tpl func.tpl (17.2 KB, 151 views)
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote