且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Magento等级价格 - 买入价格中的等级价格声明为Y - javascript

更新时间:2023-11-29 21:40:04

我刚刚花了一些时间在这上面,因为它真的开始让我烦恼在我升级了客户的Magento之后网站到1.7.0.2。

I've just spent some time on this as it was really starting to bug me after I upgraded a customer's Magento site to 1.7.0.2.

这有两个部分,我将说明位置和修复,但这些不是升级证明(为此你会想要创建文件的副本并将它们放在你的主题特定的文件夹中,虽然我不确定是否有可能与JS文件有关。)

There are two parts to this, I'm going to state the locations and the fixes, but these will not be upgrade proof (for that you will want to create copies of the files and put them in your theme specific folders, although I'm not sure if it's possible with the JS file in question).

1)查看修复

在文件 / design / frontend / base / default / template / catalog / product / view / tierprices.phtml

您需要更换行 32-34

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

使用以下代码:

$_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);

这解决了因为你已经弄清楚没有正确渲染类的问题。 这是我发现此代码的地方 - 尽管它没有解决所有问题,因此JS改变了。

This fixes the issue with the class not being rendered correctly as you had already figured out. Here is where I found this code - although it didn't fix all the issues, hence the JS changes.

2)JS修复

您需要替换行 757-769

$$('.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);

这个:

//
// 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);

我希望这可以在他们一生中的几个小时内至少节省一个人。

I hope this saves at least one person a few hours of their life.

T