javascript - magento 可以更改购物车中的价格吗?

标签 javascript php jquery json magento

我修改了\magento\js\varien\product.js下的函数以满足客户的要求。效果很好,折扣将根据我们数据库中的用户信息而适用。 enter image description here

但是,当客户将商品添加到购物车时,它只显示原价,在本例中为 549.47 美元。

enter image description here

如何将折扣价插入单价和小计部分?我应该修改哪个文件才能实现此目的?

这是我的部分 JavaScript 代码(\magento\js\varien\product.js),它生成折扣价格:

var subPrice = 0; //is the price inside the option
            var subPriceincludeTax = 0;
            var discountRate = discountRateUrl; //discount base on database
            var price = priceUrl;//get the product price
            var discountedPrice = price*discountRate; // price * ourdiscount
            //var discountedSubPrice = subPrice*((100-test)/100); // custom option addition price * ourdiscounted prices
            //console.log(discountedPrice); //display the prices as int
            //console.log(discountedSubPrice);
            //console.log(test);
            Object.values(this.customPrices).each(function(el){
                if (el.excludeTax && el.includeTax) {
                    subPrice += parseFloat(el.excludeTax); // use the var factor && this will affect the price when changing option *important
                    subPriceincludeTax += parseFloat(el.includeTax);

                } else {
                    subPrice += parseFloat(el.price);
                    subPriceincludeTax += parseFloat(el.price);

                }
                var finalprice = (subPrice*discountRate+discountedPrice);//checking if getting the php
                var fomattedprice = finalprice.toFixed(2); //Convert a number into a string, keeping only two decimals
                console.log(finalprice); //tester of the final prices
                console.log(discountRate);//tester discount rate in string
                document.getElementById("finalprice").innerHTML = "<small>Your price is </small>"+ "$" + fomattedprice + "*" +"<br/><small><em>*Discount will be applied during check out</em></small>";
          });

您可以忽略这些代码,我只是想知道我应该将我的 document.getElementById("finalprice"); 结果传递到哪里才能显示折扣价格。

如果有不清楚的地方,请发表评论,也请随时编辑我的问题。

提前致谢。

最佳答案

您需要修改

frontend/default/your_theme/template/checkout/item/default.phtml

此文件负责显示购物车中的产品及其信息。您可以在此处进行更改以查看所需的输出。

希望这会有所帮助。

关于javascript - magento 可以更改购物车中的价格吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29207171/

相关文章:

javascript - 写入数组时出现错误

javascript - Asp.net 客户端验证错误消息不断显示来自 jquery 的值更改

javascript - 有没有办法访问 HTML 的 CSS 部分中的 JavaScript 字符串变量?

php - 如何检查数据库中是否有添加的记录

javascript - 使用 jquery ajax 返回两个值

如果按下 control + s,Javascript 将执行功能

php - 有人使用index.html吗?

javascript - GTM、事件 - 点击、目标 - 链接、GA 事件 - 空

javascript - 将此 JavaScript 代码转换为 jQuery

php - JQuery 自动完成返回选中的复选框