javascript - 单击图像按钮会增加购物车价格 - Magento

标签 javascript php jquery html magento

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

enter image description here

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

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

非常感谢任何建议。

最佳答案

这是简单的 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;
}

我不知道这是否是您要找的内容,但希望对您有所帮助。

关于javascript - 单击图像按钮会增加购物车价格 - Magento,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32260085/

相关文章:

php - jQuery PLUpload 如何重命名文件名?

jquery - 在缩略图上单击在其他 div 中拉起视频

Jquery如何更改具有相同类的三个 "div"的值

javascript - 如何在不重复的情况下随机访问所有数组

javascript - (window).scrollTop 函数在第一次单击时不会触发

javascript - 如何将 getAccessToken 与 fetch 功能集成,以将数据从 DRF 后端加载到 React 前端?

javascript - 使用 javascript 重定向/更改超链接

php - 使用 FFMPEG/Laravel 在 shell_exec() 之后更新数据库

javascript - 使用 JQUERY 缩小中心图像?

javascript - 错误: TypeError: Cannot call method 'replace' of undefined