简体   繁体   English

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

[英]Is it possible to change the price in the shopping cart in magento?

I have modified the function under \\magento\\js\\varien\\product.js in order to satisfy my client's requirement. 我已经修改了\\ magento \\ js \\ varien \\ product.js下的功能,以满足客户的要求。 It works fine, the discount will apply due to the users information from our database. 它工作正常,由于我们数据库中的用户信息,因此可以享受折扣。 在此处输入图片说明

But when the customer add an item to cart, it only shows the original price which is $549.47 in this example. 但是,当客户将商品添加到购物车时,此示例中仅显示原始价格549.47美元。

在此处输入图片说明

How can i insert the discounted price into the unit price and subtotal section? 如何将折扣价插入单价和小计部分? Which file should i modify in order to achieve this? 为此,我应该修改哪个文件?

Here's part of my javascript codes(\\magento\\js\\varien\\product.js) which generate the discounted price: 这是我的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>";
          });

You can ignore these bunch of codes, i just want to know where should i pass my document.getElementById("finalprice"); 您可以忽略这些代码,我只想知道应该在哪里传递document.getElementById("finalprice"); result in order to show the discounted price. 结果以显示折扣价。

Please leave a comment if there's something unclear, also do feel free to edit my question. 如果有不清楚的地方,请发表评论,也可以随时编辑我的问题。

Thanks in advance. 提前致谢。

You need to modify 您需要修改

frontend/default/your_theme/template/checkout/item/default.phtml 前端/默认/ your_theme /模板/结算/项目/ default.phtml

This file is responsible for displaying the products and their information in the cart. 该文件负责在购物车中显示产品及其信息。 Here you can make the changes to see the desired output. 您可以在此处进行更改以查看所需的输出。

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM