I am working on Commerce 13.21.0. I am facing an issue where the cart total doesnt seem to be getting updated after overriding the LineItem calculator. I am overriding the CalculateExtendedPrice method of ILineItemCalculator to increase the extended price of a line item by $10 if a line item requires customization.
public class CustomLineItemCalculator : DefaultLineItemCalculator
{
public CustomLineItemCalculator(ITaxCalculator taxCalculator) : base(taxCalculator)
{
}
protected override Money CalculateExtendedPrice(ILineItem lineItem, Currency currency)
{
var price = base.CalculateExtendedPrice(lineItem, currency);
var option = lineItem.Properties[Constant.LineItem.TextOption] as string;
var message = lineItem.Properties[Constant.LineItem.CustomizationText] as string;
if (!string.IsNullOrWhiteSpace(option) && option == "Add custom text + $10" && !string.IsNullOrWhiteSpace(message))
{
var baseAmount = price.Amount;
price = new Money(baseAmount + 10, currency);
}
return price;
}
}
Above is the code, a straight forward override and I am also making sure that the CustomLineItemCalculator is registreted as the ILineItemCalulator implementation during initialization.
I can also see the extended price being computed properly in the DB:
But inspite of all this the cart total is still $170.
@Jeroen : Thank you for the reply, that did the trick. I was able to override CalculateDiscountedPrice of DefaultLineItemCalculator and I see the price being updated.
@Quan: Thank you for the reply, I am working on Foundation. Hence, I registered CustomLineItemCalculator onto the ILineItemCalculator service. And I did that in the initialization of Foundation.Commerce. My follow up question is that shouldn't the expectation be that CalculateExtendedPrice result in the orderform totals to also be updated? As both CalculateDiscountedPrice and CalculateExtendedPrice update the extended price of the line item. And from there onwards it is used by the shipping and orderform calculator.
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
Hi,
I am working on Commerce 13.21.0. I am facing an issue where the cart total doesnt seem to be getting updated after overriding the LineItem calculator. I am overriding the CalculateExtendedPrice method of ILineItemCalculator to increase the extended price of a line item by $10 if a line item requires customization.
Above is the code, a straight forward override and I am also making sure that the CustomLineItemCalculator is registreted as the ILineItemCalulator implementation during initialization.
I can also see the extended price being computed properly in the DB:
But inspite of all this the cart total is still $170.