@@ -167,7 +167,7 @@ define(['jquery', 'underscore', 'jquery/ui'], function ($, _) {
167
167
jsonConfig : { } , // option's json config
168
168
jsonSwatchConfig : { } , // swatch's json config
169
169
selectorProduct : '.product-info-main' , // selector of parental block of prices and swatches (need to know where to seek for price block)
170
- selectorProductPrice : '.price-final-price .price' , // selector of price wrapper (need to know where set price)
170
+ selectorProductPrice : '[data-role=priceBox]' , // selector of price wrapper (need to know where set price)
171
171
numberToShow : false , // number of controls to show (false or zero = show all)
172
172
onlySwatches : false , // show only swatch controls
173
173
enableControlLabel : true , // enable label for control
@@ -603,21 +603,48 @@ define(['jquery', 'underscore', 'jquery/ui'], function ($, _) {
603
603
_UpdatePrice : function ( ) {
604
604
var $widget = this ,
605
605
$product = $widget . element . parents ( $widget . options . selectorProduct ) ,
606
- price = $product . find ( '[data-price-amount]' ) . data ( 'price-amount' ) ;
606
+ $productPrice = $product . find ( this . options . selectorProductPrice ) ,
607
+ options = _ . object ( _ . keys ( $widget . optionsMap ) , { } ) ,
608
+ result ;
607
609
608
610
$widget . element . find ( '.' + $widget . options . classes . attributeClass + '[option-selected]' ) . each ( function ( ) {
609
- var id = $ ( this ) . attr ( 'attribute-id' ) ;
610
- var option = $ ( this ) . attr ( 'option-selected' ) ;
611
+ var attributeId = $ ( this ) . attr ( 'attribute-id' ) ,
612
+ selectedOptionId = $ ( this ) . attr ( 'option-selected' ) ;
613
+
614
+ options [ attributeId ] = selectedOptionId ;
615
+ } ) ;
616
+
617
+ result = $widget . options . jsonConfig . optionPrices [ _ . findKey ( $widget . options . jsonConfig . index , options ) ] ;
618
+
619
+ $productPrice . trigger (
620
+ 'updatePrice' ,
621
+ {
622
+ 'prices' : $widget . _getPrices ( result , $productPrice . priceBox ( 'option' ) . prices )
623
+ }
624
+ ) ;
625
+
626
+ } ,
611
627
612
- price = $widget . optionsMap [ id ] [ option ] . price ;
628
+ /**
629
+ * Get prices
630
+ * @param {Object } newPrices
631
+ * @returns {Object }
632
+ * @private
633
+ */
634
+ _getPrices : function ( newPrices , displayPrices ) {
635
+ var $widget = this ;
636
+
637
+ if ( _ . isEmpty ( newPrices ) ) {
638
+ newPrices = $widget . options . jsonConfig . prices ;
639
+ }
640
+
641
+ _ . each ( displayPrices , function ( price , code ) {
642
+ if ( newPrices [ code ] ) {
643
+ displayPrices [ code ] . amount = newPrices [ code ] . amount - displayPrices [ code ] . amount ;
644
+ }
613
645
} ) ;
614
646
615
- $product
616
- . find ( $widget . options . selectorProductPrice )
617
- . text ( $widget . options . jsonConfig . template . replace (
618
- '<%- data.price %>' ,
619
- price . formatMoney ( 2 )
620
- ) ) ;
647
+ return displayPrices ;
621
648
} ,
622
649
623
650
/**
0 commit comments