Javascript 是否可以更改magento购物车的价格?
我修改了\magento\js\varien\product.js下的函数,以满足客户的要求。它工作良好,折扣将适用于用户信息从我们的数据库。 但当客户将商品添加到购物车时,它只显示原始价格,在本例中为$549.47 如何将折扣价格插入单价和小计部分?为了实现这一点,我应该修改哪个文件 下面是我的部分javascript代码(\magento\js\varien\product.js),它生成折扣价格:Javascript 是否可以更改magento购物车的价格?,javascript,php,jquery,json,magento,Javascript,Php,Jquery,Json,Magento,我修改了\magento\js\varien\product.js下的函数,以满足客户的要求。它工作良好,折扣将适用于用户信息从我们的数据库。 但当客户将商品添加到购物车时,它只显示原始价格,在本例中为$549.47 如何将折扣价格插入单价和小计部分?为了实现这一点,我应该修改哪个文件 下面是我的部分javascript代码(\magento\js\varien\product.js),它生成折扣价格: var subPrice = 0; //is the price inside the
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>";
});
var子价格=0//价格是否在期权范围内
var子价格包括税=0;
var discountRate=discountRateUrl//基于数据库的折扣
var价格=价格URL//了解产品价格
var折扣价格=价格*折扣价格;//价格*折扣
//var折扣次级价格=次级价格*((100次测试)/100);//自定义选项附加价格*我们的折扣价格
//控制台日志(折扣价格)//将价格显示为int
//console.log(折扣单价);
//控制台日志(测试);
Object.values(this.customPrices).each(函数(el){
if(不含税和含税){
subPrice+=parseFloat(el.excludeTax);//使用var因子&&这将在更改选项时影响价格*重要
子价格包括税+=浮动(el.includeTax);
}否则{
次级价格+=浮动价格(el.价格);
分项价格包括税+=浮动价格(el.价格);
}
var finalprice=(subPrice*discountRate+discountedPrice);//检查是否获取php
var fomattedprice=finalprice.toFixed(2);//将数字转换为字符串,只保留两个小数
console.log(finalprice);//最终价格的测试者
console.log(discountRate);//字符串中的测试人员折扣率
document.getElementById(“finalprice”).innerHTML=“您的价格为“+”$“+fomattedprice+”*“+”
*退房时将享受折扣”;
});
你可以忽略这些代码,我只是想知道我应该在哪里传递我的文档.getElementById(“finalprice”)代码>结果以显示折扣价格
如果有不清楚的地方,请留下评论,也请随意编辑我的问题
提前感谢。您需要修改
frontend/default/your_theme/template/checkout/item/default.phtml
此文件负责在购物车中显示产品及其信息。在这里,您可以进行更改以查看所需的输出
希望这会有所帮助。我在\frontend\your\u theme\default\template\checkout\cart\item\default.phml中有我的文件,这是您提到的同一个文件吗?顺便说一下,我假设修改这个文件不会改变发票,是吗?你能告诉我发票的文件名吗?谢谢,阿顿1004.)是,它是同一个文件。否,这不会更改发票。您可以通过启用“管理”面板的模板路径提示来查看文件路径。请注意查看此内容。通过启用管理面板的模板路径提示,您可以看到路径。如果你有问题,你可以问