gpt4 book ai didi

javascript - Magento:bundle.js 中捆绑产品的 'Bug' 的等级定价 "Price as Configured"

转载 作者:行者123 更新时间:2023-11-28 01:30:00 26 4
gpt4 key购买 nike

我在弄清楚如何获取 bundle 页面的“已配置价格”部分以使用层定价进行更新时遇到了一些困难。

现在,如果我在捆绑产品中有一个复选框选择,并且单击该复选框将其添加到捆绑中,则“配置的价格”将更新为产品的全价,而不是分级定价(默认)选择的数量在等级定价范围内)。

现在我正在浏览/skin/frontend/base/default/js/bundle.js 文件,并在选择价格方法下看到以下内容:

selectionPrice: function(optionId, selectionId) {

.................

if (this.config.priceType == '0') {
price = this.config.options[optionId].selections[selectionId].price;
tierPrice = this.config.options[optionId].selections[selectionId].tierPrice;

for (var i=0; i < tierPrice.length; i++) {
if (Number(tierPrice[i].price_qty) <= qty && Number(tierPrice[i].price) <= price) {
price = tierPrice[i].price;
}
}
} else {
selection = this.config.options[optionId].selections[selectionId];
if (selection.priceType == '0') {
price = selection.priceValue;
} else {
price = (this.config.basePrice*selection.priceValue)/100;
}
}

到目前为止,我可以看出它已经开始设置:

price = this.config.options[optionId].selections[selectionId].price

现在通常如果 tierPrice 返回一个对象,它应该能够迭代它并找到等级价格(至少代码似乎是这样做的)。但是,它永远不会进入实际设置分级价格的 for 循环。在控制台中,我可以通过执行以下操作直接访问等级价格:

bundle.config.options['301'].selections['1066'].tierPrice['32000-5']

但是,Magento 代码依赖于能够调用 .....tierPrice[0] 而不是 ....tierPrice['32000-5'] 来获取每个单独的层级定价对象。调用 ....tierPrice[0] 返回未定义,并且 tierPrice.length 返回未定义。

为什么我无法使用 for 循环访问嵌套数组?我在这里有什么选择?

谢谢!

最佳答案

不幸的是,基于 JavaScript 的解决方案需要替换核心文件 bundle.js,作为替代方案,我有一个基于 PHP 的解决方案

首先的问题是这个对象根本不应该是一个对象。我们可以干预 JSON 生成并确保它实际上是一个数组。

为此,必须使用以下方法重写来重写类Mage_Catalog_Model_Product_Type_Price:

public function getTierPrice($qty = null, $product)
{
$tierPrice = parent::getTierPrice($qty, $product);
if (is_array($tierPrice)) {
return array_values($tierPrice);
}
return $tierPrice;
}

getTierPrice() 方法没有在任何地方使用,据我所知,字符串键是相关的,因此这比将生成的 JSON 分开并重新创建它更优雅。

我写了一个小扩展来修复这个问题以及另一个捆绑层定价错误,你可以从 https://github.com/sgh-it/bundletierprices 获取它。

进一步阅读: http://www.schmengler-se.de/en/2014/10/magento-buendelprodukte-staffelpreise-der-einfachen-produkte-nutzen/

关于javascript - Magento:bundle.js 中捆绑产品的 'Bug' 的等级定价 "Price as Configured",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22238691/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com