Skip to content

Commit 9963f13

Browse files
committed
Fix Tier Prices reload with changes from custom options.
This closes magento#279 for Magento 1.7. However, this functionality does not appear to be ported over to Magento 2. That is, it is not found in price-option.js
1 parent a15ecb3 commit 9963f13

File tree

3 files changed

+54
-48
lines changed

3 files changed

+54
-48
lines changed

app/code/Mage/Catalog/Block/Product/Price.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public function getTierPrices($product = null)
8080
$prices = $product->getFormatedTierPrice();
8181

8282
$res = array();
83+
$i = 0;
8384
if (is_array($prices)) {
8485
foreach ($prices as $price) {
8586
$price['price_qty'] = $price['price_qty'] * 1;
@@ -101,12 +102,15 @@ public function getTierPrices($product = null)
101102
$tierPrice = Mage::app()->getStore()->convertPrice(
102103
Mage::helper('Mage_Tax_Helper_Data')->getPrice($product, $price['website_price'])
103104
);
104-
$price['formated_price'] = Mage::app()->getStore()->formatPrice($tierPrice);
105-
$price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(
106-
Mage::app()->getStore()->convertPrice(
107-
Mage::helper('Mage_Tax_Helper_Data')->getPrice($product, $price['website_price'], true)
108-
)
105+
$price['formated_price'] = '<span class="price tier-' . $i . '">' .
106+
Mage::app()->getStore()->formatPrice($tierPrice, false) .
107+
'</<span>';
108+
$tierPriceInclTax = Mage::app()->getStore()->convertPrice(
109+
Mage::helper('Mage_Tax_Helper_Data')->getPrice($product, $price['website_price'], true)
109110
);
111+
$price['formated_price_incl_tax'] = '<span class="price tier-' . $i . '-incl-tax">' .
112+
Mage::app()->getStore()->formatPrice($tierPriceInclTax, false) .
113+
'</span>';
110114

111115
if (Mage::helper('Mage_Catalog_Helper_Data')->canApplyMsrp($product)) {
112116
$oldPrice = $product->getFinalPrice();
@@ -121,7 +125,7 @@ public function getTierPrices($product = null)
121125
$product->setFinalPrice($oldPrice);
122126
}
123127

124-
$res[] = $price;
128+
$res[$i++] = $price;
125129
}
126130
}
127131
}

app/code/Mage/Catalog/view/frontend/product/view/tierprices.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ if (Mage::helper('Mage_Weee_Helper_Data')->typeOfDisplay($_product, array(1,2,4)
186186
<?php if (!$this->getInGrouped()): ?>
187187
<?php if(($_product->getPrice() == $_product->getFinalPrice() && $_product->getPrice() > $_price['price'])
188188
|| ($_product->getPrice() != $_product->getFinalPrice() && $_product->getFinalPrice() > $_price['price'])): ?>
189-
<?php echo $this->__('and') ?>&nbsp;<strong class="benefit"><?php echo $this->__('save')?>&nbsp;<span class="percent tier-<?php echo $_index;?>"><?php echo $_price['savePercent']?></span>%
190-
<?php endif ?></strong>
189+
<?php echo $this->__('and') ?>&nbsp;<strong class="benefit"><?php echo $this->__('save')?>&nbsp;<span class="percent tier-<?php echo $_index;?>"><?php echo $_price['savePercent']?></span>%</strong>
190+
<?php endif ?>
191191
<?php endif; ?>
192192

193193
<?php if ($_catalogHelper->isShowPriceOnGesture($_product)):?>

pub/lib/varien/product.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ Product.OptionsPrice.prototype = {
581581

582582
this.optionPrices = {};
583583
this.customPrices = {};
584-
this.containers = {};
584+
this.containers = [];
585585

586586
this.displayZeroPrice = true;
587587

@@ -641,13 +641,31 @@ Product.OptionsPrice.prototype = {
641641
var priceInclTax = optionPrices[3];
642642
optionPrices = optionPrices[0];
643643

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) {
645663
var _productPrice;
646664
var _plusDisposition;
647665
var _minusDisposition;
648666
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) {
651669
_productPrice = this.productOldPrice;
652670
_plusDisposition = this.oldPlusDisposition;
653671
_minusDisposition = this.oldMinusDisposition;
@@ -658,7 +676,7 @@ Product.OptionsPrice.prototype = {
658676
}
659677
_priceInclTax = priceInclTax;
660678

661-
if (pair.value == 'old-price-'+this.productId && optionOldPrice !== undefined) {
679+
if (value == 'old-price-'+this.productId && optionOldPrice !== undefined) {
662680
price = optionOldPrice+parseFloat(_productPrice);
663681
} else if (this.specialTaxPrice == 'true' && this.priceInclTax !== undefined && this.priceExclTax !== undefined) {
664682
price = optionPrices+parseFloat(this.priceExclTax);
@@ -682,17 +700,6 @@ Product.OptionsPrice.prototype = {
682700
var incl = excl + tax;
683701
}
684702

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-
});
696703
excl += subPrice;
697704
incl += subPriceincludeTax;
698705

@@ -708,11 +715,11 @@ Product.OptionsPrice.prototype = {
708715
excl += parseFloat(nonTaxable);
709716
incl += parseFloat(nonTaxable);
710717

711-
if (pair.value == 'price-including-tax-'+this.productId) {
718+
if (value == 'price-including-tax-'+this.productId) {
712719
price = incl;
713-
} else if (pair.value == 'price-excluding-tax-'+this.productId) {
720+
} else if (value == 'price-excluding-tax-'+this.productId) {
714721
price = excl;
715-
} else if (pair.value == 'old-price-'+this.productId) {
722+
} else if (value == 'old-price-'+this.productId) {
716723
if (this.showIncludeTax || this.showBothPrices) {
717724
price = incl;
718725
} else {
@@ -734,40 +741,35 @@ Product.OptionsPrice.prototype = {
734741
formattedPrice = '';
735742
}
736743

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;
741748
}
742749
} 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;
746753
}
747754
}
748755
};
749756
}.bind(this));
750757

751758
for (var i = 0; i < this.tierPrices.length; i++) {
759+
var tierPrice = 0, tierPriceInclTax = 0;
752760
$$('.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);
755763
}, this);
756764
$$('.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);
759767
}, this);
760768
$$('.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;
771773
});
772774
}, this);
773775
}

0 commit comments

Comments
 (0)