@@ -223,37 +223,42 @@ define([
223
223
* Updates product final and base price according to tier prices
224
224
*/
225
225
updateProductTierPrice : function updateProductTierPrice ( ) {
226
- var productQty = $ ( this . qtyInfo ) . val ( ) ,
227
- tierPrice ,
228
- prices = { 'prices' : { } } ,
229
- i ;
226
+ var originalPrice ,
227
+ prices = { 'prices' : { } } ;
230
228
231
229
if ( this . options . prices . finalPrice ) {
232
- var originalPrice = this . options . prices . finalPrice . amount ;
233
-
234
- for ( i = 0 ; i < this . options . priceConfig . tierPrices . length ; i ++ ) {
235
- if ( productQty >= this . options . priceConfig . tierPrices [ i ] . qty ) {
236
- tierPrice = this . options . priceConfig . tierPrices [ i ] . price ;
237
- }
238
- }
239
- prices . prices . finalPrice = { 'amount' : tierPrice - originalPrice } ;
230
+ originalPrice = this . options . prices . finalPrice . amount ;
231
+ prices . prices . finalPrice = { 'amount' : this . getPrice ( 'price' ) - originalPrice } ;
240
232
}
241
233
242
234
if ( this . options . prices . basePrice ) {
243
- var originalBasePrice = this . options . prices . basePrice . amount ,
244
- tierBasePrice ,
245
- tierPriceItem ;
246
-
247
- for ( i = 0 ; i < this . options . priceConfig . tierPrices . length ; i ++ ) {
248
- tierPriceItem = this . options . priceConfig . tierPrices [ i ] ;
249
- if ( productQty >= tierPriceItem . qty && tierPriceItem . basePrice ) {
250
- tierBasePrice = tierPriceItem . basePrice ;
251
- }
252
- }
253
- prices . prices . basePrice = { 'amount' : tierBasePrice - originalBasePrice } ;
235
+ originalPrice = this . options . prices . basePrice . amount ;
236
+ prices . prices . basePrice = { 'amount' : this . getPrice ( 'basePrice' ) - originalPrice } ;
254
237
}
255
238
256
239
this . updatePrice ( prices ) ;
240
+ } ,
241
+
242
+ /**
243
+ * Returns price.
244
+ *
245
+ * @param {String } priceKey
246
+ * @returns {Number }
247
+ */
248
+ getPrice : function ( priceKey ) {
249
+ var productQty = $ ( this . qtyInfo ) . val ( ) ,
250
+ result ,
251
+ tierPriceItem ,
252
+ i ;
253
+
254
+ for ( i = 0 ; i < this . options . priceConfig . tierPrices . length ; i ++ ) {
255
+ tierPriceItem = this . options . priceConfig . tierPrices [ i ] ;
256
+ if ( productQty >= tierPriceItem . qty && tierPriceItem [ priceKey ] ) {
257
+ result = tierPriceItem [ priceKey ] ;
258
+ }
259
+ }
260
+
261
+ return result ;
257
262
}
258
263
} ) ;
259
264
0 commit comments