Gen*_*eno 6 javascript magento
在1.6多个版本的Magento中存在一个突出的错误,当选择一个选项时,等级价格的节省百分比默认为100%.其他贡献者建议在747行附近更改product.js
for (var i = 0; i < this.tierPrices.length; i++) {
Run Code Online (Sandbox Code Playgroud)
成为
for (var i = 0; i > this.tierPrices.length; i++) {
Run Code Online (Sandbox Code Playgroud)
这解决了%节省的问题,但从未执行过代码块.我绝不是Javascript专家,但是当选择选项时,此块似乎更新了层级价格和%节省.我想找到问题的根源,而不是"评论出来".
根据我在Firebug中的调试,我注意到product.js中的等级价格类是错误的,因此,检索的等级价格为0,这说明为什么%节省总是100%.Firebug显示价格为
class="tier-prices product-pricing">
Buy 10 for
<span class="price">$40.00</span>
Run Code Online (Sandbox Code Playgroud)
而product.js正试图使用
$$('.price.tier-' + i).each(function (el) {
Run Code Online (Sandbox Code Playgroud)
如果您将上述内容更改为
$$('.tier-prices .price).each(function (el) {
Run Code Online (Sandbox Code Playgroud)
检索层级价格,但对于产品的多个层级价格,无法单独引用它们.上面的"价格"类没有声明唯一标识符或迭代编号.
在等级价格中,class ="price"在哪里?在tierprices.phtml的代码中,它看起来像这样
<?php echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price'])?>
Run Code Online (Sandbox Code Playgroud)
我刚刚花了一些时间,因为在我将客户的Magento网站升级到1.7.0.2后,它真的开始让我烦恼.
这有两个部分,我将说明位置和修复,但这些不是升级证明(为此你需要创建文件的副本并将它们放在主题特定的文件夹中,尽管我'我不确定是否有可能与JS文件有关).
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);
Run Code Online (Sandbox Code Playgroud)
使用以下代码:
$_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);
Run Code Online (Sandbox Code Playgroud)
这解决了正如您已经想到的那样无法正确呈现类的问题.这是我发现这段代码的地方 - 虽然它没有修复所有问题,因此JS改变了.
2)JS修复
在文件中js/Varien/product.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);
Run Code Online (Sandbox Code Playgroud)
有了这个:
//
// 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);
Run Code Online (Sandbox Code Playgroud)
我希望这能节省至少一个人几个小时的生命.
Ť