Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento tier prices-BUY x for Y中tier prices的类声明-javascript_Javascript_Magento - Fatal编程技术网

Magento tier prices-BUY x for Y中tier prices的类声明-javascript

Magento tier prices-BUY x for Y中tier prices的类声明-javascript,javascript,magento,Javascript,Magento,Magento的1.6+版本中存在一个突出的缺陷,当选择一个选项时,层价格的%节省默认为100%。其他贡献者建议将product.js从第747行更改为 for (var i = 0; i < this.tierPrices.length; i++) { 这解决了节省%的问题,但从未执行该代码块。我绝不是Javascript专家,但当选择选项时,此块似乎正在更新层价格和%的节省。我想找到问题的根源,而不是“评论出来” 从我在Firebug中的调试中,我注意到product.js中tier

Magento的1.6+版本中存在一个突出的缺陷,当选择一个选项时,层价格的%节省默认为100%。其他贡献者建议将product.js从第747行更改为

for (var i = 0; i < this.tierPrices.length; i++) {
这解决了节省%的问题,但从未执行该代码块。我绝不是Javascript专家,但当选择选项时,此块似乎正在更新层价格和%的节省。我想找到问题的根源,而不是“评论出来”

从我在Firebug中的调试中,我注意到product.js中tier price的类是错误的,因此,检索到的tier price为0,这解释了为什么%的节省总是100%。 Firebug将价格显示为

class="tier-prices product-pricing">   
        Buy 10 for  
        <span class="price">$40.00</span>
如果您将上述内容更改为

$$('.tier-prices .price).each(function (el) {
会检索到层次价格,但对于产品上的多个层次价格,无法单独引用它们。上面的类“price”没有声明唯一标识符或迭代编号

层级价格的class=“price”在哪里声明?在tierprices.phtml的代码中,它如下所示

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

部分
class=“price”
是来自
Mage\u Directory\u Model\u Currency::formatPrecision()
的结果,当
$this->formatPrice()
或在更深的模型层中格式化价格时执行 使用
Mage::helper('core')->formatPrice()


您可以通过扩展(并重写)
Mage\u目录\u模型\u货币来添加唯一标识符
,但请注意
formatPrecision
到处都在使用。因此,您可以编写自己的帮助器/模型逻辑来格式化分层价格。

我刚刚花了一些时间在这方面,因为在我将客户的Magento站点升级到1.7.0.2之后,它确实开始困扰我

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

1)视图修复

在文件
/design/frontend/base/default/template/catalog/product/view/tierplices.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的变化

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);
为此:

//
// 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);
我希望这至少能挽救一个人几个小时的生命


T

谢谢,工作得很好。别忘了如果你的皮肤中有一个定制的product.js,你应该在那里修改它。谢谢你,你为我节省了很多时间!
$$('.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);