Why is GetListPrices in our PriceCalculatorDecorator called multiple times?

We are trying to implement a service decorator for IPriceCalculator, where the price is either to be replaced by an other value or discounted by some percentage from the list price. We are facing issues however since GetListPrices seems to be called multiple times, causing the percentage discounts to be stacked giving to much discount for the user. Why does this happen and why is GetListPrice called multiple times?

Example code (simplified), where we give a discount of 10% to all users on all products. Will cause the end price displayed on product page to be around 27% lower than the actual list price.

[Litium.Runtime.DependencyInjection.ServiceDecorator(typeof(IPriceCalculator))]
    internal class PriceCalculatorDecorator : IPriceCalculator
    {
        private readonly IPriceCalculator _parent;
        private readonly SecurityContextService _securityContextService;

        public PriceCalculatorDecorator(IPriceCalculator parent, SecurityContextService securityContextService)
        {
            _parent = parent;
            _securityContextService = securityContextService;
        }

        public IDictionary<Guid, PriceCalculatorResult> GetListPrices(PriceCalculatorArgs calculatorArgs, params PriceCalculatorItemArgs[] itemArgs)
        {
            var parentRes = _parent.GetListPrices(calculatorArgs, itemArgs);

            foreach (var item in parentRes.Values)
            {
                item.PriceExcludingVat *= 0.9M;
            }

            return parentRes;
        }

        public ICollection<ProductPriceList> GetPriceLists(PriceCalculatorArgs calculatorArgs)
        {
            var parentRes = _parent.GetPriceLists(calculatorArgs);

            return parentRes;
        }

Litium version: 8.12.0

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.