Reputation: 1145
I have modified the function under \magento\js\varien\product.js in order to satisfy my client's requirement. 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.
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:
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");
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.
Upvotes: 1
Views: 738
Reputation: 2128
You need to modify
frontend/default/your_theme/template/checkout/item/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.
Upvotes: 1