1/** 2 * Magento 3 * 4 * NOTICE OF LICENSE 5 * 6 * This source file is subject to the Academic Free License (AFL 3.0) 7 * that is bundled with this package in the file LICENSE_AFL.txt. 8 * It is also available through the world-wide-web at this URL: 9 * http://opensource.org/licenses/afl-3.0.php 10 * If you did not receive a copy of the license and are unable to 11 * obtain it through the world-wide-web, please send an email 12 * to [email protected] so we can send you a copy immediately. 13 * 14 * DISCLAIMER 15 * 16 * Do not edit or add to this file if you wish to upgrade Magento to newer 17 * versions in the future. If you wish to customize Magento for your 18 * needs please refer to http://www.magento.com for more information. 19 * 20 * @category Varien 21 * @package js 22 * @copyright Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com) 23 * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24 */ 25 26var Product = Product || {}; 27 28/**************************** PRICE RELOADER ********************************/ 29Product.OptionsPrice = Class.create(); 30Product.OptionsPrice.prototype = { 31 initialize: function(config) { 32 this.productId = config.productId; 33 this.priceFormat = config.priceFormat; 34 this.includeTax = config.includeTax; 35 this.defaultTax = config.defaultTax; 36 this.currentTax = config.currentTax; 37 this.productPrice = config.productPrice; 38 this.showIncludeTax = config.showIncludeTax; 39 this.showBothPrices = config.showBothPrices; 40 this.productOldPrice = config.productOldPrice; 41 this.priceInclTax = config.priceInclTax; 42 this.priceExclTax = config.priceExclTax; 43 this.skipCalculate = config.skipCalculate; /** @deprecated after 1.5.1.0 */ 44 this.duplicateIdSuffix = config.idSuffix; 45 this.specialTaxPrice = config.specialTaxPrice; 46 this.tierPrices = config.tierPrices; 47 this.tierPricesInclTax = config.tierPricesInclTax; 48 49 this.oldPlusDisposition = config.oldPlusDisposition; 50 this.plusDisposition = config.plusDisposition; 51 this.plusDispositionTax = config.plusDispositionTax; 52 53 this.oldMinusDisposition = config.oldMinusDisposition; 54 this.minusDisposition = config.minusDisposition; 55 56 this.exclDisposition = config.exclDisposition; 57 58 this.optionPrices = {}; 59 this.customPrices = {}; 60 this.containers = {}; 61 62 this.displayZeroPrice = true; 63 64 this.initPrices(); 65 }, 66 67 setDuplicateIdSuffix: function(idSuffix) { 68 this.duplicateIdSuffix = idSuffix; 69 }, 70 71 initPrices: function() { 72 this.containers[0] = 'product-price-' + this.productId; 73 this.containers[1] = 'bundle-price-' + this.productId; 74 this.containers[2] = 'price-including-tax-' + this.productId; 75 this.containers[3] = 'price-excluding-tax-' + this.productId; 76 this.containers[4] = 'old-price-' + this.productId; 77 }, 78 79 changePrice: function(key, price) { 80 this.optionPrices[key] = price; 81 }, 82 83 addCustomPrices: function(key, price) { 84 this.customPrices[key] = price; 85 }, 86 getOptionPrices: function() { 87 var price = 0; 88 var nonTaxable = 0; 89 var oldPrice = 0; 90 var priceInclTax = 0; 91 var currentTax = this.currentTax; 92 $H(this.optionPrices).each(function(pair) { 93 if ('undefined' != typeof(pair.value.price) && 'undefined' != typeof(pair.value.oldPrice)) { 94 price += parseFloat(pair.value.price); 95 oldPrice += parseFloat(pair.value.oldPrice); 96 } else if (pair.key == 'nontaxable') { 97 nonTaxable = pair.value; 98 } else if (pair.key == 'priceInclTax') { 99 priceInclTax += pair.value; 100 } else if (pair.key == 'optionsPriceInclTax') { 101 priceInclTax += pair.value * (100 + currentTax) / 100; 102 } else { 103 price += parseFloat(pair.value); 104 oldPrice += parseFloat(pair.value); 105 } 106 }); 107 return [price, nonTaxable, oldPrice, priceInclTax]; 108 }, 109 110 reload: function() { 111 var price; 112 var formattedPrice; 113 var optionPrices = this.getOptionPrices(); 114 var nonTaxable = optionPrices[1]; 115 var optionOldPrice = optionPrices[2]; 116 var priceInclTax = optionPrices[3]; 117 optionPrices = optionPrices[0]; 118
119 $H(this.containers).each(function(pair) { 120 var _productPrice; 121 var _plusDisposition; 122 var _minusDisposition; 123 var _priceInclTax; 124 var excl; 125 var incl; 126 var tax; 127 if ($(pair.value)) { 128 if (pair.value == 'old-price-'+this.productId && this.productOldPrice != this.productPrice) { 129 _productPrice = this.productOldPrice; 130 _plusDisposition = this.oldPlusDisposition; 131 _minusDisposition = this.oldMinusDisposition; 132 } else { 133 _productPrice = this.productPrice; 134 _plusDisposition = this.plusDisposition; 135 _minusDisposition = this.minusDisposition; 136 } 137 _priceInclTax = priceInclTax; 138 139 if (pair.value == 'old-price-'+this.productId && optionOldPrice !== undefined) { 140 price = optionOldPrice+parseFloat(_productPrice); 141 } else if (this.specialTaxPrice == 'true' && this.priceInclTax !== undefined && this.priceExclTax !== undefined) { 142 price = optionPrices+parseFloat(this.priceExclTax); 143 _priceInclTax += this.priceInclTax; 144 } else { 145 price = optionPrices+parseFloat(_productPrice); 146 _priceInclTax += parseFloat(_productPrice) * (100 + this.currentTax) / 100; 147 } 148 149 if (this.specialTaxPrice == 'true') { 150 excl = price; 151 incl = _priceInclTax; 152 } else if (this.includeTax == 'true') { 153 // tax = tax included into product price by admin 154 tax = price / (100 + this.defaultTax) * this.defaultTax; 155 excl = price - tax; 156 incl = excl*(1+(this.currentTax/100)); 157 } else { 158 tax = price * (this.currentTax / 100); 159 excl = price; 160 incl = excl + tax; 161 } 162 163 var subPrice = 0; 164 var subPriceincludeTax = 0; 165 Object.values(this.customPrices).each(function(el){ 166 if (el.excludeTax && el.includeTax) { 167 subPrice += parseFloat(el.excludeTax); 168 subPriceincludeTax += parseFloat(el.includeTax); 169 } else { 170 subPrice += parseFloat(el.price); 171 subPriceincludeTax += parseFloat(el.price); 172 } 173 }); 174 excl += subPrice; 175 incl += subPriceincludeTax; 176 177 if (typeof this.exclDisposition == 'undefined') { 178 excl += parseFloat(_plusDisposition); 179 } 180 181 incl += parseFloat(_plusDisposition) + parseFloat(this.plusDispositionTax); 182 excl -= parseFloat(_minusDisposition); 183 incl -= parseFloat(_minusDisposition); 184 185 //adding nontaxlable part of options 186 excl += parseFloat(nonTaxable); 187 incl += parseFloat(nonTaxable); 188 189 if (pair.value == 'price-including-tax-'+this.productId) { 190 price = incl; 191 } else if (pair.value == 'price-excluding-tax-'+this.productId) { 192 price = excl; 193 } else if (pair.value == 'old-price-'+this.productId) { 194 if (this.showIncludeTax || this.showBothPrices) { 195 price = incl; 196 } else { 197 price = excl; 198 } 199 } else { 200 if (this.showIncludeTax) { 201 price = incl; 202 } else { 203 price = excl; 204 } 205 } 206 207 if (price < 0) price = 0; 208 209 if (price > 0 || this.displayZeroPrice) { 210 formattedPrice = this.formatPrice(price); 211 } else { 212 formattedPrice = ''; 213 } 214 215 if ($(pair.value).select('.price')[0]) { 216 $(pair.value).select('.price')[0].innerHTML = formattedPrice; 217 if ($(pair.value+this.duplicateIdSuffix) && $(pair.value+this.duplicateIdSuffix).select('.price')[0]) { 218 $(pair.value+this.duplicateIdSuffix).select('.price')[0].innerHTML = formattedPrice; 219 } 220 } else { 221 $(pair.value).innerHTML = formattedPrice; 222 if ($(pair.value+this.duplicateIdSuffix)) { 223 $(pair.value+this.duplicateIdSuffix).innerHTML = formattedPrice; 224 } 225 } 226 }; 227 }.bind(this)); 228 229 if (typeof(skipTierPricePercentUpdate) === "undefined" && typeof(this.tierPrices) !== "undefined") { 230 for (var i = 0; i < this.tierPrices.length; i++) { 231 $$('.benefit').each(function(el) { 232 var parsePrice = function(html) { 233 var format = this.priceFormat; 234 var decimalSymbol = format.decimalSymbol === undefined ? "," : format.decimalSymbol; 235 var regexStr = '[^0-9-' + decimalSymbol + ']'; 236 //remove all characters except number and decimal symbol 237 html = html.replace(new RegExp(regexStr, 'g'), ''); 238 html = html.replace(decimalSymbol, '.'); 239 return parseFloat(html); 240 }.bind(this); 241 242 var updateTierPriceInfo = function(priceEl, tierPriceDiff, tierPriceEl, benefitEl) { 243 if (typeof(tierPriceEl) === "undefined") { 244 //tierPrice is not shown, e.g., MAP, no need to update the tier price info 245 return; 246 } 247 var price = parsePrice(priceEl.innerHTML); 248 var tierPrice = price + tierPriceDiff; 249 250 tierPriceEl.innerHTML = this.formatPrice(tierPrice); 251 252 var $percent = Selector.findChildElements(benefitEl, ['.percent.tier-' + i]); 253 $percent.each(function(el) { 254 el.innerHTML = Math.ceil(100 - ((100 / price) * tierPrice)); 255 }); 256 }.bind(this); 257 258 var tierPriceElArray = $$('.tier-price.tier-' + i + ' .price'); 259 if (this.showBothPrices) { 260 var containerExclTax = $(this.containers[3]); 261 var tierPriceExclTaxDiff = this.tierPrices[i]; 262 var tierPriceExclTaxEl = tierPriceElArray[0]; 263 updateTierPriceInfo(containerExclTax, tierPriceExclTaxDiff, tierPriceExclTaxEl, el); 264 var containerInclTax = $(this.containers[2]); 265 var tierPriceInclTaxDiff = this.tierPricesInclTax[i]; 266 var tierPriceInclTaxEl = tierPriceElArray[1]; 267 updateTierPriceInfo(containerInclTax, tierPriceInclTaxDiff, tierPriceInclTaxEl, el); 268 } else if (this.showIncludeTax) { 269 var container = $(this.containers[0]); 270 var tierPriceInclTaxDiff = this.tierPricesInclTax[i]; 271 var tierPriceInclTaxEl = tierPriceElArray[0]; 272 updateTierPriceInfo(container, tierPriceInclTaxDiff, tierPriceInclTaxEl, el); 273 } else { 274 var container = $(this.containers[0]); 275 var tierPriceExclTaxDiff = this.tierPrices[i]; 276 var tierPriceExclTaxEl = tierPriceElArray[0]; 277 updateTierPriceInfo(container, tierPriceExclTaxDiff, tierPriceExclTaxEl, el); 278 } 279 }, this); 280 } 281 } 282 283 }, 284 formatPrice: function(price) { 285 return formatCurrency(price, this.priceFormat); 286 } 287};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.