Magento等级价格 - 买入价格中的等级价格声明为Y - javascript [英] Magento tier prices - class declaration for tier price in BUY x for Y - javascript

查看:95
本文介绍了Magento等级价格 - 买入价格中的等级价格声明为Y - javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Magento的1.6+版本中存在一个突出的错误,当选择一个选项时,等级价格的节省百分比默认为100%。其他贡献者建议在第747行更改product.js

There is an outstanding bug in 1.6+ versions of Magento where the % savings for tier prices defaults to 100% when an option is selected. Other contributors have suggested changing product.js around line 747 from

for (var i = 0; i < this.tierPrices.length; i++) {

for (var i = 0; i > this.tierPrices.length; i++) {

这解决了%Saving的问题,但该代码块从未执行过。我绝不是Javascript专家,但是当选择选项时,此块似乎更新了层级价格和%节省。我想找到问题的根源,而不是评论出来。

This resolves the issue with % savings but that code block is never executed. I am by no means a Javascript expert but this block appears to be updating the tier price and % savings when options are selected. I wanted to find the root of the issue, rather than 'commenting it out'.

根据我在Firebug中的调试,我注意到product.js中的等级价格类是错误的,因此,检索层级价格为0,这说明为什么%节省总是100%。
Firebug将价格显示为

From my debugging in Firebug I noticed that the classes for tier price is wrong in product.js and therefore, a tier price of 0 is retrieved, which accounts for why % savings is always 100%. Firebug shows the price as

class="tier-prices product-pricing">   
        Buy 10 for  
        <span class="price">$40.00</span>

而product.js正在尝试使用

whereas product.js is attempting to retrieve the objects using

$$('.price.tier-' + i).each(function (el) {

如果您将上述内容更改为

If you change the above to

$$('.tier-prices .price).each(function (el) {

检索等级价格,但是产品的多个层级价格,没有办法单独引用它们。上面的价格类没有声明的唯一标识符或迭代编号。

the tier price is retrieved, but for more than one tier price on a product, there is no way to refer to them individually. The class "price" above does not have a unique identifier or iterative number declared.

为层级价格声明的class =price在哪里?在tierprices.phtml的代码中它看起来像这样

Where is class="price" declared for the tier price? In the code of tierprices.phtml it looks like this

<?php echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price'])?>


推荐答案

我刚刚花了一些时间在这上面,因为它真的开始让我烦恼在我升级了客户的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

这篇关于Magento等级价格 - 买入价格中的等级价格声明为Y - javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆