November Happy Hour will be moved to Thursday December 5th.

LineItemCalculator price is not getting updated on the cart

Vote:
 

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.

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.

#246619
Edited, Jan 11, 2021 5:44
Vote:
 

If I remember correctly you should also override the GetDiscountedPrice as that is used in calculating the orderfrm values

#246624
Jan 11, 2021 8:50
Siddharth Gupta - Jan 12, 2021 4:34
@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.
Vote:
 

How do you register your CustomLineItemCalculator . Is it registered for Commerce Manager also?

#246631
Jan 11, 2021 9:27
Siddharth Gupta - Jan 12, 2021 5:00
@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.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.