2
2
* Copyright © 2016 Magento. All rights reserved.
3
3
* See COPYING.txt for license details.
4
4
*/
5
+
5
6
define ( [
6
7
'jquery' ,
7
8
'Magento_Catalog/js/price-utils' ,
@@ -29,6 +30,7 @@ define([
29
30
*/
30
31
_init : function initPriceBox ( ) {
31
32
var box = this . element ;
33
+
32
34
box . trigger ( 'updatePrice' ) ;
33
35
this . cache . displayPrices = utils . deepClone ( this . options . prices ) ;
34
36
} ,
@@ -70,7 +72,8 @@ define([
70
72
updatePrice : function updatePrice ( newPrices ) {
71
73
var prices = this . cache . displayPrices ,
72
74
additionalPrice = { } ,
73
- pricesCode = [ ] ;
75
+ pricesCode = [ ] ,
76
+ priceValue , origin , final ;
74
77
75
78
this . cache . additionalPriceObject = this . cache . additionalPriceObject || { } ;
76
79
@@ -89,19 +92,19 @@ define([
89
92
pricesCode = _ . keys ( additional ) ;
90
93
}
91
94
_ . each ( pricesCode , function ( priceCode ) {
92
- var priceValue = additional [ priceCode ] || { } ;
95
+ priceValue = additional [ priceCode ] || { } ;
93
96
priceValue . amount = + priceValue . amount || 0 ;
94
97
priceValue . adjustments = priceValue . adjustments || { } ;
95
98
96
99
additionalPrice [ priceCode ] = additionalPrice [ priceCode ] || {
97
- 'amount' : 0 ,
98
- 'adjustments' : { }
99
- } ;
100
- additionalPrice [ priceCode ] . amount = 0 + ( additionalPrice [ priceCode ] . amount || 0 )
101
- + priceValue . amount ;
100
+ 'amount' : 0 ,
101
+ 'adjustments' : { }
102
+ } ;
103
+ additionalPrice [ priceCode ] . amount = 0 + ( additionalPrice [ priceCode ] . amount || 0 ) +
104
+ priceValue . amount ;
102
105
_ . each ( priceValue . adjustments , function ( adValue , adCode ) {
103
- additionalPrice [ priceCode ] . adjustments [ adCode ] = 0
104
- + ( additionalPrice [ priceCode ] . adjustments [ adCode ] || 0 ) + adValue ;
106
+ additionalPrice [ priceCode ] . adjustments [ adCode ] = 0 +
107
+ ( additionalPrice [ priceCode ] . adjustments [ adCode ] || 0 ) + adValue ;
105
108
} ) ;
106
109
} ) ;
107
110
} ) ;
@@ -110,8 +113,8 @@ define([
110
113
this . cache . displayPrices = utils . deepClone ( this . options . prices ) ;
111
114
} else {
112
115
_ . each ( additionalPrice , function ( option , priceCode ) {
113
- var origin = this . options . prices [ priceCode ] || { } ,
114
- final = prices [ priceCode ] || { } ;
116
+ origin = this . options . prices [ priceCode ] || { } ;
117
+ final = prices [ priceCode ] || { } ;
115
118
option . amount = option . amount || 0 ;
116
119
origin . amount = origin . amount || 0 ;
117
120
origin . adjustments = origin . adjustments || { } ;
@@ -127,6 +130,7 @@ define([
127
130
this . element . trigger ( 'reloadPrice' ) ;
128
131
} ,
129
132
133
+ /*eslint-disable no-extra-parens*/
130
134
/**
131
135
* Render price unit block.
132
136
*/
@@ -135,16 +139,19 @@ define([
135
139
priceTemplate = mageTemplate ( this . options . priceTemplate ) ;
136
140
137
141
_ . each ( this . cache . displayPrices , function ( price , priceCode ) {
138
- price . final = _ . reduce ( price . adjustments , function ( memo , amount ) {
142
+ price . final = _ . reduce ( price . adjustments , function ( memo , amount ) {
139
143
return memo + amount ;
140
144
} , price . amount ) ;
141
145
142
146
price . formatted = utils . formatPrice ( price . final , priceFormat ) ;
143
147
144
- $ ( '[data-price-type="' + priceCode + '"]' , this . element ) . html ( priceTemplate ( { data : price } ) ) ;
148
+ $ ( '[data-price-type="' + priceCode + '"]' , this . element ) . html ( priceTemplate ( {
149
+ data : price
150
+ } ) ) ;
145
151
} , this ) ;
146
152
} ,
147
153
154
+ /*eslint-enable no-extra-parens*/
148
155
/**
149
156
* Overwrites initial (default) prices object.
150
157
* @param {Object } prices
@@ -177,6 +184,7 @@ define([
177
184
var box = this . element ,
178
185
priceHolders = $ ( '[data-price-type]' , box ) ,
179
186
prices = this . options . prices ;
187
+
180
188
this . options . productId = box . data ( 'productId' ) ;
181
189
182
190
if ( _ . isEmpty ( prices ) ) {
@@ -199,10 +207,7 @@ define([
199
207
_setDefaultsFromPriceConfig : function _setDefaultsFromPriceConfig ( ) {
200
208
var config = this . options . priceConfig ;
201
209
202
- if ( config ) {
203
- if ( + config . productId !== + this . options . productId ) {
204
- return ;
205
- }
210
+ if ( config && config . prices ) {
206
211
this . options . prices = config . prices ;
207
212
}
208
213
}
0 commit comments