【问题标题】:Image button increases cart price when clicked - Magento单击图像按钮会增加购物车价格 - Magento
【发布时间】:2015-08-27 21:54:55
【问题描述】:

我目前正在开发一个使用图像按钮向订单添加预定义消息的插件。

然而,我想做的是为每个按钮分配一个价格,该价格也会添加到订单中。有点像分配给每个按钮的自定义选项,但我可以自己编写代码。

这可能吗?我找不到任何信息来使用按钮/代码调整购物车的价格。

非常感谢任何建议。

【问题讨论】:

  • 我想我可能拥有它...我可以为我想要的价格设置其他产品并将它们分配给按钮。我发现这个问题/答案似乎是正确的!
  • 您尝试做的似乎与this tutorial 的内容非常相似。不同之处在于本教程使用<select> 菜单来选择选项,而您想使用离散按钮(图像) - 但原理应该相同。

标签: javascript php jquery html magento


【解决方案1】:

这是简单的javascript,除非你想在服务器端做,这很容易但需要mysql。

HTML 代码:

<img src="" onclick="item_1()"> //just add the src (path) and some style.
<img src="" onclick="item_2()"> //if you need a third just repeat the same and change the numbers.

<p id="total_order">$0</p> //that's the paragraph that shows the total bill (can be a div too)

JAVASCRIPT:

var order = 0;
var price_1 = "price"; //simply change "price" for the price you want
var price_2 = "price";

function item_1() {
order += price_1; //increments the order value by the price of the 1st item
document.getElementById("total_order").innerHTML = "$"+order;
}
//same function repeated but with different number
function item_2() { 
order += price_2;
document.getElementById("total_order").innerHTML = "$"+order;
}

我不知道这是否是您正在寻找的,但我希望它会有所帮助。

【讨论】:

    猜你喜欢
    • 2013-10-30
    • 2013-02-18
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    相关资源
    最近更新 更多