Magento 层级价格 - BUY x for Y 中层级价格的类声明 - javascript [英] Magento tier prices - class declaration for tier price in BUY x for Y - javascript

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

问题描述

在选择选项时,在Magento中有1.6个+版本的Magento中有一个未突出的错误,默认值为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++) {

这解决了节省 % 的问题,但永远不会执行该代码块.I am by no means a Javascript expert but this block appears to be updating the tier price and % savings when options are selected.我想找到问题的根源,而不是注释掉".

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) {

如果你把上面的改成

$$('.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 修复

在文件 js/Varien/product.js 中,您需要替换行 757-769:

in the file js/Varien/product.js you need to replace lines 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 层级价格 - BUY x for Y 中层级价格的类声明 - javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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