是否有可能在购物车中更改magento的价格?

时间:2015-03-23 09:49:30

标签: 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");结果以显示折扣价。

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

提前致谢。

1 个答案:

答案 0 :(得分:1)

您需要修改

  

前端/默认/ your_theme /模板/结帐/项目/ default.phtml

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

希望这会有所帮助。