Further restriction on price lists

Hi,

We have a case where price lists with no organisation links remain on products. When a price list is present on a product and has no organisations, it seems that it can be chosen as the price for a product where the customer’s price list is not present.

Our solution is to simply delete the price lists with no organisation links, but the client feels that a stricter solution is in order.

What is the best practice for preventing a price list with no organisations to be selected as price for a product?

Litium version: 7

1 Like

You could try adding a decorator that filters out pricelists without a organization link. With Litium 7.4 you could instead use permissions to control this (visitor wouldn’t have read access to a pricelist).

Something like this, tested with Litium 7.2.3.

using Litium.Products;
using Litium.Products.PriceCalculator;
using Litium.Runtime.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Litium.Accelerator.Services
{
	[ServiceDecorator(typeof(IPriceCalculator))]
	public class OrganizationPriceCalculatorDecorator : IPriceCalculator
	{
		private readonly IPriceCalculator _parentResolver;
		private readonly PriceListService _priceListService;

		public OrganizationPriceCalculatorDecorator(IPriceCalculator parentResolver, PriceListService priceListService)
		{
			_parentResolver = parentResolver;
			_priceListService = priceListService;
		}

		public IDictionary<Guid, PriceCalculatorResult> GetListPrices(PriceCalculatorArgs calculatorArgs, params PriceCalculatorItemArgs[] itemArgs)
		{
			LimitPricelists(calculatorArgs);

			return _parentResolver.GetListPrices(calculatorArgs, itemArgs);
		}

		public ICollection<PriceList> GetPriceLists(PriceCalculatorArgs calculatorArgs)
		{
			LimitPricelists(calculatorArgs);

			return _parentResolver.GetPriceLists(calculatorArgs);
		}

		private void LimitPricelists(PriceCalculatorArgs calculatorArgs)
		{
			var allowedPriceLists = _priceListService.GetAll().Where(list => list.OrganizationLinks.Count > 0).Select(x => x.SystemId).ToList();
			calculatorArgs.PriceListSystemIds = allowedPriceLists;
		}
	}
}
2 Likes

Thanks Nils! This works like a charm :slight_smile:

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