How to do calculation in _ProductTierPrices.cshtml

11 months ago

How to do a calculation to show the percentage discount in TierPrice instead of listing the actual prices?

Price: $100,
Tier price 10pcs: $90
Tier price 20pcs: $80
Tier price 50pcs: $70

Calculate to
Tier price 10pcs: 10% OFF "by (($100-$90)/$100)"
Tier price 20pcs: 20% OFF
Tier price 50pcs: 30% OFF

Calculate in in _ProductTierPrices.cshtml file, no source code

Can anyone help?

Thank you
11 months ago
1.You need to add new field in TierPriceModel
public decimal PriceValue {get;set;}
2. I am not sure which nop version are you using? so you need to just set PriceValue = without formatting.
3. either do code at controller level or same page you use PriceValue so it should be achieve your requirement.
11 months ago
n _ProductTierPrices.cshtml page we can't get the product original price. It should be requires to show percentage base calculation.

I think you need to modify ProductTemplate.Simple.cshtml page for using Product original price.
@await Html.PartialAsync("_ProductTierPrices", Model.TierPrices) replace with @await Html.PartialAsync("_ProductTierPrices", Model)

then make change in _ProductTierPrices.cshtml file according to use ProductDetailsModel model whole page lke Model.TirePrice in foreach loop etc..

Percentage Calculation should be

@foreach (var tierPrice in Model.TierPrices)
    var tirepriceStr = tierPrice.Price.Replace("$", "");
    var tirepriceValue = Convert.ToDecimal(tirepriceStr);
    var subtractedPrice = Convert.ToDecimal(Model.ProductPrice.PriceValue - tirepriceValue);
    var calulatedPercentage = (subtractedPrice / Model.ProductPrice.PriceValue) * 100;
    <td class="item-price">
        @calulatedPercentage.ToString("0.##")% OFF