@@ -28,7 +28,8 @@ define([
28
28
controlContainer : 'dd' , // should be eliminated
29
29
priceFormat : { } ,
30
30
isFixedPrice : false ,
31
- optionTierPricesBlocksSelector : '#option-tier-prices-{1} [data-role="selection-tier-prices"]'
31
+ optionTierPricesBlocksSelector : '#option-tier-prices-{1} [data-role="selection-tier-prices"]' ,
32
+ isOptionsInitialized : false
32
33
} ;
33
34
34
35
$ . widget ( 'mage.priceBundle' , {
@@ -53,20 +54,37 @@ define([
53
54
priceBox = $ ( this . options . priceBoxSelector , form ) ,
54
55
qty = $ ( this . options . qtyFieldSelector , form ) ;
55
56
56
- if ( priceBox . data ( 'magePriceBox' ) &&
57
- priceBox . priceBox ( 'option' ) &&
58
- priceBox . priceBox ( 'option' ) . priceConfig
59
- ) {
60
- if ( priceBox . priceBox ( 'option' ) . priceConfig . optionTemplate ) {
61
- this . _setOption ( 'optionTemplate' , priceBox . priceBox ( 'option' ) . priceConfig . optionTemplate ) ;
57
+ this . _updatePriceBox ( ) ;
58
+ priceBox . on ( 'price-box-initialized' , this . _updatePriceBox . bind ( this ) ) ;
59
+ options . on ( 'change' , this . _onBundleOptionChanged . bind ( this ) ) ;
60
+ qty . on ( 'change' , this . _onQtyFieldChanged . bind ( this ) ) ;
61
+ } ,
62
+
63
+ /**
64
+ * Update price box config with bundle option prices
65
+ * @private
66
+ */
67
+ _updatePriceBox : function ( ) {
68
+ var form = this . element ,
69
+ options = $ ( this . options . productBundleSelector , form ) ,
70
+ priceBox = $ ( this . options . priceBoxSelector , form ) ;
71
+
72
+ if ( ! this . options . isOptionsInitialized ) {
73
+ if ( priceBox . data ( 'magePriceBox' ) &&
74
+ priceBox . priceBox ( 'option' ) &&
75
+ priceBox . priceBox ( 'option' ) . priceConfig
76
+ ) {
77
+ if ( priceBox . priceBox ( 'option' ) . priceConfig . optionTemplate ) { //eslint-disable-line max-depth
78
+ this . _setOption ( 'optionTemplate' , priceBox . priceBox ( 'option' ) . priceConfig . optionTemplate ) ;
79
+ }
80
+ this . _setOption ( 'priceFormat' , priceBox . priceBox ( 'option' ) . priceConfig . priceFormat ) ;
81
+ priceBox . priceBox ( 'setDefault' , this . options . optionConfig . prices ) ;
82
+ this . options . isOptionsInitialized = true ;
62
83
}
63
- this . _setOption ( 'priceFormat' , priceBox . priceBox ( 'option' ) . priceConfig . priceFormat ) ;
64
- priceBox . priceBox ( 'setDefault' , this . options . optionConfig . prices ) ;
84
+ this . _applyOptionNodeFix ( options ) ;
65
85
}
66
- this . _applyOptionNodeFix ( options ) ;
67
86
68
- options . on ( 'change' , this . _onBundleOptionChanged . bind ( this ) ) ;
69
- qty . on ( 'change' , this . _onQtyFieldChanged . bind ( this ) ) ;
87
+ return this ;
70
88
} ,
71
89
72
90
/**
0 commit comments