Skip to content

Magento 1.7 Product with Options and Tiered pricing showing wrong percentage discount (100%)

This was bugging me at work today, found the answer at Stack Overflow

http://stackoverflow.com/questions/13504056/magento-tier-prices-class-declaration-for-tier-price-in-buy-x-for-y-javascri/16022796#16022796

Essentially, when you have a product set up for tiered pricing everything works great until you add custom options to the product.  Then instead of saying "25% off" it just says "100% off"

The solution (in case of link rot)

Edit The View File

Replace lines 34 - 34 which should read as follows:

$_product = $this->getProduct();
$_tierPrices = $this->getTierPrices();
$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);

With this:

$_product = $this->getProduct();
$_tierPrices = array();

foreach($this->getTierPrices() as $index => $info) {
    $_tierPrices[$index] = $info;
    $_tierPrices[$index]['formated_price'] = str_replace('class="price"', 'class="price tier-'.$index.'"', $info['formated_price']);
    $_tierPrices[$index]['formated_price_incl_tax'] = str_replace('class="price"', 'class="price tier-'.$index.' tier-'.$index.'-incl-tax"', $info['formated_price_incl_tax']);
}
$_finalPriceInclTax = $this->helper('tax')->getPrice($_product, $_product->getFinalPrice(), true);

And save your file.

 

Javascript Update

At this point your tiered price will probably be displaying NaN%, we need to let the javascript functions know of the change and fix a looping bug.

Open (and backup)

/js/Varien/product.js

Replace Lines 757 - 769 which should look like 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));
    });
}, this);

With this:

//
// Code fixed to prevent the redundant inner loop and to use actual tiered pricing in calculation
// It also takes the optional price variants into consideration (eg: +£2 for a blue tshirt)
// Note: I've made this comment deliberately large, to keep the line numbers in sync
//
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);
$$('.percent.tier-' + i).each(function (el) {
    el.innerHTML = Math.ceil(100 - ((100 / price) * (this.tierPrices[i] + parseFloat(optionPrices))));
}, this);

Again the link... http://stackoverflow.com/questions/13504056/magento-tier-prices-class-declaration-for-tier-price-in-buy-x-for-y-javascri/16022796#16022796

Thanks to Tr1stan and well done for finding this!!

1 thought on “Magento 1.7 Product with Options and Tiered pricing showing wrong percentage discount (100%)”

  1. You can try Magento Percentage Tier Price extension by BSSCommerce, check it out here: http://bsscommerce.com/magento-percentage-off-tiered-pricing.html

    The extension extends default Magento Tier Price function by allowing admins to define tier prices as a percentage.

    See more useful features:
    +Easily set up tier price based on standard price or group price
    +Set tier price in a fixed amount or in percentage
    +Automatically update tier price when price is changed

    Hope it helps!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

s2Member®