javascript - Unreachable code in varien/configurable.js Magento -
javascript - Unreachable code in varien/configurable.js Magento -
taking @ magento source file seek understand why can't move varien/configurable.js whithout throwing error extension, google closure compiler shrink it, returns error @ line 267:
jsc_unreachable_code: unreachable code @ line 267 character 8 if($('product-price-'+this.config.productid)){ ^
in particular these piece of code:
getattributeoptions: function(attributeid){ if(this.config.attributes[attributeid]){ homecoming this.config.attributes[attributeid].options; } }, could explain me why throw out warning?
this whole code:
/** * magento * * notice of license * * source file subject academic free license (afl 3.0) * bundled bundle in file license_afl.txt. * available through world-wide-web @ url: * http://opensource.org/licenses/afl-3.0.php * if did not receive re-create of license , unable * obtain through world-wide-web, please send email * license@magentocommerce.com can send re-create immediately. * * disclaimer * * not edit or add together file if wish upgrade magento newer * versions in future. if wish customize magento * needs please refer http://www.magentocommerce.com more information. * * @category varien * @package js * @copyright copyright (c) 2014 magento inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php academic free license (afl 3.0) */ if (typeof product == 'undefined') { var product = {}; } /**************************** configurable product **************************/ product.config = class.create(); product.config.prototype = { initialize: function(config){ this.config = config; this.taxconfig = this.config.taxconfig; if (config.containerid) { this.settings = $$('#' + config.containerid + ' ' + '.super-attribute-select'); } else { this.settings = $$('.super-attribute-select'); } this.state = new hash(); this.pricetemplate = new template(this.config.template); this.prices = config.prices; // set default values config if (config.defaultvalues) { this.values = config.defaultvalues; } // overwrite defaults url var separatorindex = window.location.href.indexof('#'); if (separatorindex != -1) { var paramsstr = window.location.href.substr(separatorindex+1); var urlvalues = paramsstr.toqueryparams(); if (!this.values) { this.values = {}; } (var in urlvalues) { this.values[i] = urlvalues[i]; } } // overwrite defaults inputs values if needed if (config.inputsinitialized) { this.values = {}; this.settings.each(function(element) { if (element.value) { var attributeid = element.id.replace(/[a-z]*/, ''); this.values[attributeid] = element.value; } }.bind(this)); } // set events check select reloads this.settings.each(function(element){ event.observe(element, 'change', this.configure.bind(this)) }.bind(this)); // fill state this.settings.each(function(element){ var attributeid = element.id.replace(/[a-z]*/, ''); if(attributeid && this.config.attributes[attributeid]) { element.config = this.config.attributes[attributeid]; element.attributeid = attributeid; this.state[attributeid] = false; } }.bind(this)) // init settings dropdown var childsettings = []; for(var i=this.settings.length-1;i>=0;i--){ var prevsetting = this.settings[i-1] ? this.settings[i-1] : false; var nextsetting = this.settings[i+1] ? this.settings[i+1] : false; if (i == 0){ this.fillselect(this.settings[i]) } else { this.settings[i].disabled = true; } $(this.settings[i]).childsettings = childsettings.clone(); $(this.settings[i]).prevsetting = prevsetting; $(this.settings[i]).nextsetting = nextsetting; childsettings.push(this.settings[i]); } // set values inputs this.configureforvalues(); document.observe("dom:loaded", this.configureforvalues.bind(this)); }, configureforvalues: function () { if (this.values) { this.settings.each(function(element){ var attributeid = element.attributeid; element.value = (typeof(this.values[attributeid]) == 'undefined')? '' : this.values[attributeid]; this.configureelement(element); }.bind(this)); } }, configure: function(event){ var element = event.element(event); this.configureelement(element); }, configureelement : function(element) { this.reloadoptionlabels(element); if(element.value){ this.state[element.config.id] = element.value; if(element.nextsetting){ element.nextsetting.disabled = false; this.fillselect(element.nextsetting); this.resetchildren(element.nextsetting); } } else { this.resetchildren(element); } this.reloadprice(); }, reloadoptionlabels: function(element){ var selectedprice; if(element.options[element.selectedindex].config && !this.config.stableprices){ selectedprice = parsefloat(element.options[element.selectedindex].config.price) } else{ selectedprice = 0; } for(var i=0;i<element.options.length;i++){ if(element.options[i].config){ element.options[i].text = this.getoptionlabel(element.options[i].config, element.options[i].config.price-selectedprice); } } }, resetchildren : function(element){ if(element.childsettings) { for(var i=0;i<element.childsettings.length;i++){ element.childsettings[i].selectedindex = 0; element.childsettings[i].disabled = true; if(element.config){ this.state[element.config.id] = false; } } } }, fillselect: function(element){ var attributeid = element.id.replace(/[a-z]*/, ''); var options = this.getattributeoptions(attributeid); this.clearselect(element); element.options[0] = new option('', ''); element.options[0].innerhtml = this.config.choosetext; var prevconfig = false; if(element.prevsetting){ prevconfig = element.prevsetting.options[element.prevsetting.selectedindex]; } if(options) { var index = 1; for(var i=0;i<options.length;i++){ var allowedproducts = []; if(prevconfig) { for(var j=0;j<options[i].products.length;j++){ if(prevconfig.config.allowedproducts && prevconfig.config.allowedproducts.indexof(options[i].products[j])>-1){ allowedproducts.push(options[i].products[j]); } } } else { allowedproducts = options[i].products.clone(); } if(allowedproducts.size()>0){ options[i].allowedproducts = allowedproducts; element.options[index] = new option(this.getoptionlabel(options[i], options[i].price), options[i].id); if (typeof options[i].price != 'undefined') { element.options[index].setattribute('price', options[i].price); } element.options[index].config = options[i]; index++; } } } }, getoptionlabel: function(option, price){ var cost = parsefloat(price); if (this.taxconfig.includetax) { var taxation = cost / (100 + this.taxconfig.defaulttax) * this.taxconfig.defaulttax; var excl = cost - tax; var incl = excl*(1+(this.taxconfig.currenttax/100)); } else { var taxation = cost * (this.taxconfig.currenttax / 100); var excl = price; var incl = excl + tax; } if (this.taxconfig.showincludetax || this.taxconfig.showbothprices) { cost = incl; } else { cost = excl; } var str = option.label; if(price){ if (this.taxconfig.showbothprices) { str+= ' ' + this.formatprice(excl, true) + ' (' + this.formatprice(price, true) + ' ' + this.taxconfig.incltaxtitle + ')'; } else { str+= ' ' + this.formatprice(price, true); } } homecoming str; }, formatprice: function(price, showsign){ var str = ''; cost = parsefloat(price); if(showsign){ if(price<0){ str+= '-'; cost = -price; } else{ str+= '+'; } } var roundedprice = (math.round(price*100)/100).tostring(); if (this.prices && this.prices[roundedprice]) { str+= this.prices[roundedprice]; } else { str+= this.pricetemplate.evaluate({price:price.tofixed(2)}); } homecoming str; }, clearselect: function(element){ for(var i=element.options.length-1;i>=0;i--){ element.remove(i); } }, getattributeoptions: function(attributeid){ if(this.config.attributes[attributeid]){ homecoming this.config.attributes[attributeid].options; } }, reloadprice: function(){ if (this.config.disablepricereload) { return; } var cost = 0; var oldprice = 0; for(var i=this.settings.length-1;i>=0;i--){ var selected = this.settings[i].options[this.settings[i].selectedindex]; if(selected.config){ cost += parsefloat(selected.config.price); oldprice += parsefloat(selected.config.oldprice); } } optionsprice.changeprice('config', {'price': price, 'oldprice': oldprice}); optionsprice.reload(); homecoming price; if($('product-price-'+this.config.productid)){ $('product-price-'+this.config.productid).innerhtml = price; } this.reloadoldprice(); }, reloadoldprice: function(){ if (this.config.disablepricereload) { return; } if ($('old-price-'+this.config.productid)) { var cost = parsefloat(this.config.oldprice); for(var i=this.settings.length-1;i>=0;i--){ var selected = this.settings[i].options[this.settings[i].selectedindex]; if(selected.config){ price+= parsefloat(selected.config.price); } } if (price < 0) cost = 0; cost = this.formatprice(price); if($('old-price-'+this.config.productid)){ $('old-price-'+this.config.productid).innerhtml = price; } } } }
please check below code in reloadoldprice function:
homecoming price; if($('product-price-'+this.config.productid)){ $('product-price-'+this.config.productid).innerhtml = price; } this.reloadoldprice(); when using return price; return statement doesn't allow next code run. unreachable, hence garbage. either utilize status if want function stop there in specific situations or set homecoming statement @ end of function or remove return price; if not required.
javascript magento unreachable-code
Comments
Post a Comment