给花店的。我有一些已经有尺寸属性的产品。我还需要添加产品选项(附加),如花瓶或个性化卡,这将改变产品的价格。这些选项并不是所有的产品,只有那些我将选择,有时它可能只是一个或另一个选项。我尝试将这些属性添加为单选按钮,但是单选按钮没有显示(仅显示组标题),但是产品属性对于这种类型的选项不正确。我对各种解决方案都持开放态度。提前谢谢。
发布于 2021-07-11 18:04:05
我想出了下面的解决方案。我意识到页面中的javascript变量包含了组合价格。我的问题是,在单选按钮上单击url是用replaceState参数更改的。所以我使用了下面的代码,改变按钮标签。
var _wr = function(type) {
var orig = history[type];
return function() {
var rv = orig.apply(this, arguments);
var e = new Event(type);
e.arguments = arguments;
window.dispatchEvent(e);
return rv;
};
};
history.pushState = _wr('pushState'), history.replaceState = _ wr('replaceState');
// Use it like this:
window.addEventListener('replaceState', function(e) {
var productPrices = [];
var productNames = [];
var buttonNames = [];
var targetDivs = document.getElementById("add-to-cart-or-refresh").getElementsByClassName("radio-label");
for (k in accessoriesTablePrice[randomMainProductId].combinations) {
productPrices.push(accessoriesTablePrice[randomMainProductId].combinations[k].price);
};
for (d in accessoriesTablePrice[randomMainProductId].combinations) {
productNames.push(accessoriesTablePrice[randomMainProductId].combinations[d].name);
};
for (i = 0; i < targetDivs.length; i++) {
var targetDiv = targetDivs[i];
if(productPrices[i] >=0) {
buttonNames.push(productNames[i] + "<br>" + productPrices[i] + ",00 €");
targetDiv.innerHTML = productNames[i] + "<br>" + productPrices[i] + ",00 €";
}
}
});
});发布于 2021-05-20 00:36:26
单选按钮通常意味着用户只能选择单选组的一个选项,因为这是普通HTML单选按钮的默认选项。
这听起来像是<input type="checkbox">的用例。
编辑:在重新阅读你的问题后,我看到你正在寻找Prestashop的解决方案,而我还没有用过。我把我的答案留在这里,以防它能帮助你走上正确的道路。
https://webmasters.stackexchange.com/questions/134442
复制相似问题