Skip to content

Commit

Permalink
Fix Tier Prices reload with changes from custom options.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kabel committed Sep 9, 2013
1 parent a15ecb3 commit 9963f13
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 48 deletions.
16 changes: 10 additions & 6 deletions app/code/Mage/Catalog/Block/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function getTierPrices($product = null)
$prices = $product->getFormatedTierPrice();

$res = array();
$i = 0;
if (is_array($prices)) {
foreach ($prices as $price) {
$price['price_qty'] = $price['price_qty'] * 1;
Expand All @@ -101,12 +102,15 @@ public function getTierPrices($product = null)
$tierPrice = Mage::app()->getStore()->convertPrice(
Mage::helper('Mage_Tax_Helper_Data')->getPrice($product, $price['website_price'])
);
$price['formated_price'] = Mage::app()->getStore()->formatPrice($tierPrice);
$price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(
Mage::app()->getStore()->convertPrice(
Mage::helper('Mage_Tax_Helper_Data')->getPrice($product, $price['website_price'], true)
)
$price['formated_price'] = '<span class="price tier-' . $i . '">' .
Mage::app()->getStore()->formatPrice($tierPrice, false) .
'</<span>';
$tierPriceInclTax = Mage::app()->getStore()->convertPrice(
Mage::helper('Mage_Tax_Helper_Data')->getPrice($product, $price['website_price'], true)
);
$price['formated_price_incl_tax'] = '<span class="price tier-' . $i . '-incl-tax">' .
Mage::app()->getStore()->formatPrice($tierPriceInclTax, false) .
'</span>';

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

$res[] = $price;
$res[$i++] = $price;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ if (Mage::helper('Mage_Weee_Helper_Data')->typeOfDisplay($_product, array(1,2,4)
<?php if (!$this->getInGrouped()): ?>
<?php if(($_product->getPrice() == $_product->getFinalPrice() && $_product->getPrice() > $_price['price'])
|| ($_product->getPrice() != $_product->getFinalPrice() && $_product->getFinalPrice() > $_price['price'])): ?>
<?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>%
<?php endif ?></strong>
<?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>
<?php endif ?>
<?php endif; ?>

<?php if ($_catalogHelper->isShowPriceOnGesture($_product)):?>
Expand Down
82 changes: 42 additions & 40 deletions pub/lib/varien/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ Product.OptionsPrice.prototype = {

this.optionPrices = {};
this.customPrices = {};
this.containers = {};
this.containers = [];

this.displayZeroPrice = true;

Expand Down Expand Up @@ -641,13 +641,31 @@ Product.OptionsPrice.prototype = {
var priceInclTax = optionPrices[3];
optionPrices = optionPrices[0];

$H(this.containers).each(function(pair) {
var subPrice = 0;
var subPriceincludeTax = 0;
Object.values(this.customPrices).each(function(el){
if (el.excludeTax && el.includeTax) {
subPrice += parseFloat(el.excludeTax);
subPriceincludeTax += parseFloat(el.includeTax);
} else {
subPrice += parseFloat(el.price);
subPriceincludeTax += parseFloat(el.price);
}
});

var priceDiff = optionPrices + subPrice;
if (this.lastReloadPrice !== undefined && this.lastReloadPrice === priceDiff) {
return;
}
this.lastReloadPrice = priceDiff;

$A(this.containers).each(function(value) {
var _productPrice;
var _plusDisposition;
var _minusDisposition;
var _priceInclTax;
if ($(pair.value)) {
if (pair.value == 'old-price-'+this.productId && this.productOldPrice != this.productPrice) {
if ($(value)) {
if (value == 'old-price-'+this.productId && this.productOldPrice != this.productPrice) {
_productPrice = this.productOldPrice;
_plusDisposition = this.oldPlusDisposition;
_minusDisposition = this.oldMinusDisposition;
Expand All @@ -658,7 +676,7 @@ Product.OptionsPrice.prototype = {
}
_priceInclTax = priceInclTax;

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

var subPrice = 0;
var subPriceincludeTax = 0;
Object.values(this.customPrices).each(function(el){
if (el.excludeTax && el.includeTax) {
subPrice += parseFloat(el.excludeTax);
subPriceincludeTax += parseFloat(el.includeTax);
} else {
subPrice += parseFloat(el.price);
subPriceincludeTax += parseFloat(el.price);
}
});
excl += subPrice;
incl += subPriceincludeTax;

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

if (pair.value == 'price-including-tax-'+this.productId) {
if (value == 'price-including-tax-'+this.productId) {
price = incl;
} else if (pair.value == 'price-excluding-tax-'+this.productId) {
} else if (value == 'price-excluding-tax-'+this.productId) {
price = excl;
} else if (pair.value == 'old-price-'+this.productId) {
} else if (value == 'old-price-'+this.productId) {
if (this.showIncludeTax || this.showBothPrices) {
price = incl;
} else {
Expand All @@ -734,40 +741,35 @@ Product.OptionsPrice.prototype = {
formattedPrice = '';
}

if ($(pair.value).select('.price')[0]) {
$(pair.value).select('.price')[0].innerHTML = formattedPrice;
if ($(pair.value+this.duplicateIdSuffix) && $(pair.value+this.duplicateIdSuffix).select('.price')[0]) {
$(pair.value+this.duplicateIdSuffix).select('.price')[0].innerHTML = formattedPrice;
if ($(value).select('.price')[0]) {
$(value).select('.price')[0].innerHTML = formattedPrice;
if ($(value+this.duplicateIdSuffix) && $(value+this.duplicateIdSuffix).select('.price')[0]) {
$(value+this.duplicateIdSuffix).select('.price')[0].innerHTML = formattedPrice;
}
} else {
$(pair.value).innerHTML = formattedPrice;
if ($(pair.value+this.duplicateIdSuffix)) {
$(pair.value+this.duplicateIdSuffix).innerHTML = formattedPrice;
$(value).innerHTML = formattedPrice;
if ($(value+this.duplicateIdSuffix)) {
$(value+this.duplicateIdSuffix).innerHTML = formattedPrice;
}
}
};
}.bind(this));

for (var i = 0; i < this.tierPrices.length; i++) {
var tierPrice = 0, tierPriceInclTax = 0;
$$('.price.tier-' + i).each(function (el) {
var price = this.tierPrices[i] + parseFloat(optionPrices);
el.innerHTML = this.formatPrice(price);
tierPrice = this.tierPrices[i] + optionPrices + subPrice;
el.innerHTML = this.formatPrice(tierPrice);
}, this);
$$('.price.tier-' + i + '-incl-tax').each(function (el) {
var price = this.tierPricesInclTax[i] + parseFloat(optionPrices);
el.innerHTML = this.formatPrice(price);
tierPriceInclTax = this.tierPricesInclTax[i] + priceInclTax + subPriceincludeTax;
el.innerHTML = this.formatPrice(tierPriceInclTax);
}, this);
$$('.benefit').each(function (el) {
var parsePrice = function (html) {
return parseFloat(/\d+\.?\d*/.exec(html));
};
var container = $(this.containers[3]) ? this.containers[3] : this.containers[0];
var price = parsePrice($(container).innerHTML);
var tierPrice = $$('.price.tier-' + i);
tierPrice = tierPrice.length ? parseInt(tierPrice[0].innerHTML, 10) : 0;
var $percent = Selector.findChildElements(el, ['.percent.tier-' + i]);
$percent.each(function (el) {
el.innerHTML = Math.ceil(100 - ((100 / price) * tierPrice));
var showPrice = this.showIncludeTax ? tierPriceInclTax : tierPrice,
percent = Math.ceil(100 - ((100 / price) * showPrice));
el.select('.percent.tier-' + i).each(function (el) {
el.innerHTML =percent;
});
}, this);
}
Expand Down

0 comments on commit 9963f13

Please sign in to comment.