@@ -581,7 +581,7 @@ Product.OptionsPrice.prototype = {
581
581
582
582
this . optionPrices = { } ;
583
583
this . customPrices = { } ;
584
- this . containers = { } ;
584
+ this . containers = [ ] ;
585
585
586
586
this . displayZeroPrice = true ;
587
587
@@ -641,13 +641,31 @@ Product.OptionsPrice.prototype = {
641
641
var priceInclTax = optionPrices [ 3 ] ;
642
642
optionPrices = optionPrices [ 0 ] ;
643
643
644
- $H ( this . containers ) . each ( function ( pair ) {
644
+ var subPrice = 0 ;
645
+ var subPriceincludeTax = 0 ;
646
+ Object . values ( this . customPrices ) . each ( function ( el ) {
647
+ if ( el . excludeTax && el . includeTax ) {
648
+ subPrice += parseFloat ( el . excludeTax ) ;
649
+ subPriceincludeTax += parseFloat ( el . includeTax ) ;
650
+ } else {
651
+ subPrice += parseFloat ( el . price ) ;
652
+ subPriceincludeTax += parseFloat ( el . price ) ;
653
+ }
654
+ } ) ;
655
+
656
+ var priceDiff = optionPrices + subPrice ;
657
+ if ( this . lastReloadPrice !== undefined && this . lastReloadPrice === priceDiff ) {
658
+ return ;
659
+ }
660
+ this . lastReloadPrice = priceDiff ;
661
+
662
+ $A ( this . containers ) . each ( function ( value ) {
645
663
var _productPrice ;
646
664
var _plusDisposition ;
647
665
var _minusDisposition ;
648
666
var _priceInclTax ;
649
- if ( $ ( pair . value ) ) {
650
- if ( pair . value == 'old-price-' + this . productId && this . productOldPrice != this . productPrice ) {
667
+ if ( $ ( value ) ) {
668
+ if ( value == 'old-price-' + this . productId && this . productOldPrice != this . productPrice ) {
651
669
_productPrice = this . productOldPrice ;
652
670
_plusDisposition = this . oldPlusDisposition ;
653
671
_minusDisposition = this . oldMinusDisposition ;
@@ -658,7 +676,7 @@ Product.OptionsPrice.prototype = {
658
676
}
659
677
_priceInclTax = priceInclTax ;
660
678
661
- if ( pair . value == 'old-price-' + this . productId && optionOldPrice !== undefined ) {
679
+ if ( value == 'old-price-' + this . productId && optionOldPrice !== undefined ) {
662
680
price = optionOldPrice + parseFloat ( _productPrice ) ;
663
681
} else if ( this . specialTaxPrice == 'true' && this . priceInclTax !== undefined && this . priceExclTax !== undefined ) {
664
682
price = optionPrices + parseFloat ( this . priceExclTax ) ;
@@ -682,17 +700,6 @@ Product.OptionsPrice.prototype = {
682
700
var incl = excl + tax ;
683
701
}
684
702
685
- var subPrice = 0 ;
686
- var subPriceincludeTax = 0 ;
687
- Object . values ( this . customPrices ) . each ( function ( el ) {
688
- if ( el . excludeTax && el . includeTax ) {
689
- subPrice += parseFloat ( el . excludeTax ) ;
690
- subPriceincludeTax += parseFloat ( el . includeTax ) ;
691
- } else {
692
- subPrice += parseFloat ( el . price ) ;
693
- subPriceincludeTax += parseFloat ( el . price ) ;
694
- }
695
- } ) ;
696
703
excl += subPrice ;
697
704
incl += subPriceincludeTax ;
698
705
@@ -708,11 +715,11 @@ Product.OptionsPrice.prototype = {
708
715
excl += parseFloat ( nonTaxable ) ;
709
716
incl += parseFloat ( nonTaxable ) ;
710
717
711
- if ( pair . value == 'price-including-tax-' + this . productId ) {
718
+ if ( value == 'price-including-tax-' + this . productId ) {
712
719
price = incl ;
713
- } else if ( pair . value == 'price-excluding-tax-' + this . productId ) {
720
+ } else if ( value == 'price-excluding-tax-' + this . productId ) {
714
721
price = excl ;
715
- } else if ( pair . value == 'old-price-' + this . productId ) {
722
+ } else if ( value == 'old-price-' + this . productId ) {
716
723
if ( this . showIncludeTax || this . showBothPrices ) {
717
724
price = incl ;
718
725
} else {
@@ -734,40 +741,35 @@ Product.OptionsPrice.prototype = {
734
741
formattedPrice = '' ;
735
742
}
736
743
737
- if ( $ ( pair . value ) . select ( '.price' ) [ 0 ] ) {
738
- $ ( pair . value ) . select ( '.price' ) [ 0 ] . innerHTML = formattedPrice ;
739
- if ( $ ( pair . value + this . duplicateIdSuffix ) && $ ( pair . value + this . duplicateIdSuffix ) . select ( '.price' ) [ 0 ] ) {
740
- $ ( pair . value + this . duplicateIdSuffix ) . select ( '.price' ) [ 0 ] . innerHTML = formattedPrice ;
744
+ if ( $ ( value ) . select ( '.price' ) [ 0 ] ) {
745
+ $ ( value ) . select ( '.price' ) [ 0 ] . innerHTML = formattedPrice ;
746
+ if ( $ ( value + this . duplicateIdSuffix ) && $ ( value + this . duplicateIdSuffix ) . select ( '.price' ) [ 0 ] ) {
747
+ $ ( value + this . duplicateIdSuffix ) . select ( '.price' ) [ 0 ] . innerHTML = formattedPrice ;
741
748
}
742
749
} else {
743
- $ ( pair . value ) . innerHTML = formattedPrice ;
744
- if ( $ ( pair . value + this . duplicateIdSuffix ) ) {
745
- $ ( pair . value + this . duplicateIdSuffix ) . innerHTML = formattedPrice ;
750
+ $ ( value ) . innerHTML = formattedPrice ;
751
+ if ( $ ( value + this . duplicateIdSuffix ) ) {
752
+ $ ( value + this . duplicateIdSuffix ) . innerHTML = formattedPrice ;
746
753
}
747
754
}
748
755
} ;
749
756
} . bind ( this ) ) ;
750
757
751
758
for ( var i = 0 ; i < this . tierPrices . length ; i ++ ) {
759
+ var tierPrice = 0 , tierPriceInclTax = 0 ;
752
760
$$ ( '.price.tier-' + i ) . each ( function ( el ) {
753
- var price = this . tierPrices [ i ] + parseFloat ( optionPrices ) ;
754
- el . innerHTML = this . formatPrice ( price ) ;
761
+ tierPrice = this . tierPrices [ i ] + optionPrices + subPrice ;
762
+ el . innerHTML = this . formatPrice ( tierPrice ) ;
755
763
} , this ) ;
756
764
$$ ( '.price.tier-' + i + '-incl-tax' ) . each ( function ( el ) {
757
- var price = this . tierPricesInclTax [ i ] + parseFloat ( optionPrices ) ;
758
- el . innerHTML = this . formatPrice ( price ) ;
765
+ tierPriceInclTax = this . tierPricesInclTax [ i ] + priceInclTax + subPriceincludeTax ;
766
+ el . innerHTML = this . formatPrice ( tierPriceInclTax ) ;
759
767
} , this ) ;
760
768
$$ ( '.benefit' ) . each ( function ( el ) {
761
- var parsePrice = function ( html ) {
762
- return parseFloat ( / \d + \. ? \d * / . exec ( html ) ) ;
763
- } ;
764
- var container = $ ( this . containers [ 3 ] ) ? this . containers [ 3 ] : this . containers [ 0 ] ;
765
- var price = parsePrice ( $ ( container ) . innerHTML ) ;
766
- var tierPrice = $$ ( '.price.tier-' + i ) ;
767
- tierPrice = tierPrice . length ? parseInt ( tierPrice [ 0 ] . innerHTML , 10 ) : 0 ;
768
- var $percent = Selector . findChildElements ( el , [ '.percent.tier-' + i ] ) ;
769
- $percent . each ( function ( el ) {
770
- el . innerHTML = Math . ceil ( 100 - ( ( 100 / price ) * tierPrice ) ) ;
769
+ var showPrice = this . showIncludeTax ? tierPriceInclTax : tierPrice ,
770
+ percent = Math . ceil ( 100 - ( ( 100 / price ) * showPrice ) ) ;
771
+ el . select ( '.percent.tier-' + i ) . each ( function ( el ) {
772
+ el . innerHTML = percent ;
771
773
} ) ;
772
774
} , this ) ;
773
775
}
0 commit comments