【问题标题】:Is it possible to change the price in the shopping cart in magento?是否可以在magento中更改购物车中的价格?
【发布时间】: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


    【解决方案1】:

    你需要修改

    前端/默认/your_theme/template/checkout/item/default.phtml

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

    希望这会有所帮助。

    【讨论】:

    • 我在 \frontend\your_theme\default\template\checkout\cart\item\default.phml 中有我的,这是你提到的同一个文件吗?顺便说一句,我假设修改此文件不会更改发票,是吗?请您也给我发票的文件名好吗?谢谢,aton1004。 :)
    • 是的,它是同一个文件。不,这不会更改发票。您可以通过启用管理面板的模板路径提示来查看文件路径,请注意查看stackoverflow.com/questions/22398645/…。通过启用管理面板的模板路径提示,您可以看到路径。有问题可以问
    猜你喜欢
    • 1970-01-01
    • 2013-02-18
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 2017-04-06
    • 2014-10-18
    相关资源
    最近更新 更多