@@ -7,10 +7,11 @@ define([
7
7
"jquery" ,
8
8
"underscore" ,
9
9
"mage/template" ,
10
+ "priceUtils" ,
11
+ "priceBox" ,
10
12
"jquery/ui" ,
11
- "jquery/jquery.parsequery" ,
12
- "Magento_Catalog/js/price-box"
13
- ] , function ( $ , _ , mageTemplate ) {
13
+ "jquery/jquery.parsequery"
14
+ ] , function ( $ , _ , mageTemplate , utils ) {
14
15
15
16
function getPrices ( elems ) {
16
17
var prices = { } ;
@@ -32,6 +33,7 @@ define([
32
33
superSelector : '.super-attribute-select' ,
33
34
priceHolderSelector : '.price-box' ,
34
35
state : { } ,
36
+ priceFormat : { } ,
35
37
optionTemplate : '<%= data.label %>' +
36
38
'<% if (data.finalPrice.value) { %>' +
37
39
' <%= data.finalPrice.formatted %>' +
@@ -65,9 +67,14 @@ define([
65
67
*/
66
68
_initializeOptions : function ( ) {
67
69
var priceBoxOptions = $ ( this . options . priceHolderSelector ) . priceBox ( 'option' ) ;
70
+
68
71
if ( priceBoxOptions . priceConfig && priceBoxOptions . priceConfig . optionTemplate ) {
69
72
this . options . optionTemplate = priceBoxOptions . priceConfig . optionTemplate ;
70
73
}
74
+
75
+ if ( priceBoxOptions . priceConfig && priceBoxOptions . priceConfig . priceFormat ) {
76
+ this . options . priceFormat = priceBoxOptions . priceConfig . priceFormat ;
77
+ }
71
78
this . options . optionTemplate = mageTemplate ( this . options . optionTemplate ) ;
72
79
73
80
this . options . settings = ( this . options . spConfig . containerId ) ?
@@ -388,37 +395,10 @@ define([
388
395
return {
389
396
value : price ,
390
397
name : name ,
391
- formatted : this . _formatPrice ( price , true )
398
+ formatted : utils . formatPrice ( price , this . options . priceFormat , true )
392
399
} ;
393
400
} ,
394
401
395
- /**
396
- * Format's the price of a configurable option's choice. Add sign as needed, round,
397
- * and format the rounded price with the appropriate sign.
398
- * @private
399
- * @param price An option choice's price
400
- * @param showSign Whether to show the sign as '-' or '+' in the formatted price.
401
- * @return {String } Returns the formatted price with or without the sign.
402
- */
403
- _formatPrice : function ( price , showSign ) {
404
- var str = '' ;
405
- price = parseFloat ( price ) ;
406
- if ( showSign ) {
407
- if ( price < 0 ) {
408
- str += '-' ;
409
- price = - price ;
410
- }
411
- else {
412
- str += '+' ;
413
- }
414
- }
415
- var roundedPrice = ( Math . round ( price * 100 ) / 100 ) . toString ( ) ;
416
- str = ( this . options . spConfig . prices && this . options . spConfig . prices [ roundedPrice ] ) ?
417
- str + this . options . spConfig . prices [ roundedPrice ] :
418
- str + this . options . spConfig . template . replace ( / # \{ ( .* ?) \} / , price . toFixed ( 2 ) ) ;
419
- return str ;
420
- } ,
421
-
422
402
/**
423
403
* Removes an option's selections.
424
404
* @private
0 commit comments