【发布时间】:2015-03-23 09:49:29
【问题描述】:
为了满足客户的需求,我修改了\magento\js\varien\product.js下的函数。它工作正常,由于我们数据库中的用户信息,折扣将适用。
但是当客户将商品添加到购物车时,它只显示原价,在本例中为 549.47 美元。
如何将折扣价插入单价和小计部分?为了实现这一点,我应该修改哪个文件?
这是我的 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");结果以显示折扣价。
如果有不清楚的地方请发表评论,也请随时编辑我的问题。
提前致谢。
【问题讨论】:
标签: javascript php jquery json magento