# Connect pricelist to channel

**URL:** <https://forum.litium.com/t/connect-pricelist-to-channel/1948>\
**Category:** Questions\
**Tags:** litium-7\
**Created:** [March 18, 2021, 10:39am UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948 "2021-03-18T10:39:18Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![aram](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/aram/32/19_2.png) [@aram](https://forum.litium.com/u/aram)\
**Post date:** [March 18, 2021, 10:39am UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/1 "2021-03-18T10:39:19Z")

</div>

Hi,

Is it possible to connect a pricelist to a channel somehow? The scenario is that same account can purchase order on both b2c and b2b (which are 2 different channels). The user is connected to a specific group which is in its turn connected to b2b-pricelist. so when user is logged in on b2c-channel he/she gets b2b-pricces which is incorrect. Any ideas how to solve this?

Litium version: _[7.2.0]_

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [March 18, 2021, 11:05am UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/2 "2021-03-18T11:05:28Z")

</div>

Could you add a decorator for the price calculator method `GetPriceLists` that excludes this price list if it’s the b2c channel?

Untested:

```auto
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 CustomPriceCalculator : IPriceCalculator
	{
		private readonly IPriceCalculator _parent;
		private readonly PriceListService _priceListService;

		public CustomPriceCalculator(IPriceCalculator parent, PriceListService priceListService)
		{
			_parent = parent;
			_priceListService = priceListService;
		}

		public IDictionary<Guid, PriceCalculatorResult> GetListPrices(PriceCalculatorArgs calculatorArgs, params PriceCalculatorItemArgs[] itemArgs)
		{
			calculatorArgs.PriceListSystemIds = GetPriceLists(calculatorArgs).Select(x => x.SystemId).ToList();

			return _parent.GetListPrices(calculatorArgs, itemArgs);
		}

		public ICollection<PriceList> GetPriceLists(PriceCalculatorArgs calculatorArgs)
		{
			// if channel is B2C, exclude B2B price list
			if (IsB2C()) {
				return _parent.GetPriceLists(calculatorArgs).Where(x => x.Id != "B2BPriceListId").ToList();
			}

			return _parent.GetPriceLists(calculatorArgs);
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![aram](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/aram/32/19_2.png) [@aram](https://forum.litium.com/u/aram)\
**Post date:** [March 18, 2021, 11:23am UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/3 "2021-03-18T11:23:51Z")

</div>

That could definitly be a solution, I will test and come back! Thanks Nils!

---

<div class="post-metadata">

**Author:** ![aram](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/aram/32/19_2.png) [@aram](https://forum.litium.com/u/aram)\
**Post date:** [March 22, 2021, 11:21am UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/4 "2021-03-22T11:21:21Z")

</div>

I just tested this in 2 different ways. But `GetPriceLists()` never gets called? 🤔  
I first tested it by modify `MVC/Routing/PriceCalculatorDecorator` which comes as standard with Accelerator 7.2.0. And then I actually created a custom price calculator located in same path/namespace as in ur example, but still `GetPriceLists()` doesn’t get called. Any idea why?

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [March 22, 2021, 1:54pm UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/5 "2021-03-22T13:54:08Z")

</div>

You should see it called when opening a category for example, since it’s called directly from the price filter service.

That’s also why we call it in `GetListPrices`, to ensure that when calculating a price (for when looking at a product page for example) we use our subset of price lists. Otherwise, when the original calculator calls it, it will use its own implementation. Is `GetListPrices` not called either?

---

<div class="post-metadata">

**Author:** ![aram](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/aram/32/19_2.png) [@aram](https://forum.litium.com/u/aram)\
**Post date:** [March 22, 2021, 3:37pm UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/6 "2021-03-22T15:37:44Z")

</div>

Thank you Nils!! I totaly missed this line 🙂

```auto
calculatorArgs.PriceListSystemIds = GetPriceLists(calculatorArgs).Select(x => x.SystemId).ToList();

```

I changed it and it works as expected now.

One issue that I noticed is when adding some product to the cart from e.g. b2b channel and then visit the checkout page on b2c, the orderrows in the cart will have the prices for the b2b, I hoped they were updated “automatically”, so I need to look into that. 🤔

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [March 23, 2021, 8:15am UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/7 "2021-03-23T08:15:23Z")

</div>

Do you have the code mentioned here in your `ControllerBase`?

> [@Shoppingcart with two channels and one domain](https://forum.litium.com/t/shoppingcart-with-two-channels-and-one-domain/546/2):
>
> This is a known problem in the accelerator and if you update the ControllerBase with something as below you will check and of needed set the new channel, country, market and currency on the shopping cart. using System.Linq; using System.Web.Mvc; using System.Web.Routing; using Litium.Accelerator.Builders.Menu; using Litium.Foundation.Modules.ECommerce.ShoppingCarts; using Litium.Foundation.Security; using Litium.Globalization; using Litium.Runtime.AutoMapper; using Litium.Web.Routing; using Lit…

---

<div class="post-metadata">

**Author:** ![aram](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/aram/32/19_2.png) [@aram](https://forum.litium.com/u/aram)\
**Post date:** [March 23, 2021, 8:27am UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/8 "2021-03-23T08:27:41Z")

</div>

Yes, I have it.

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [March 23, 2021, 12:54pm UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/9 "2021-03-23T12:54:34Z")

</div>

Not sure what the issue could be. I tried in a 7.2.4 with two channels on the same domain (but different prefix), and the call to `SetChannel` will trigger a re-fetch of list prices which would hit your decorator.

---

<div class="post-metadata">

**Author:** ![aram](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/aram/32/19_2.png) [@aram](https://forum.litium.com/u/aram)\
**Post date:** [March 23, 2021, 2:03pm UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/10 "2021-03-23T14:03:46Z")

</div>

I think I found the issue… in `GetPriceLists()` I use `_requestModelAccessor.RequestModel?.ChannelModel?.Channel` to check the current channel and when the call comes from `Cart.SetChannel` (see the stack trace below to see the call stack) the `_requestModelAccessor.RequestModel` is null which cause the issue. I think I will change to fetch the current channel from either the orderCarrier or store it in the http session from ControllerBase.

The call stack:

```auto
vid Litium.Accelerator.Mvc.Routing.PriceCalculatorDecorator.GetPriceLists(PriceCalculatorArgs calculatorArgs) i Src\\Litium.Accelerator.Mvc\\Routing\\PriceCalculatorDecorator.cs:rad 42
vid Litium.Accelerator.Mvc.Routing.PriceCalculatorDecorator.GetListPrices(PriceCalculatorArgs calculatorArgs, PriceCalculatorItemArgs[] itemArgs) i Src\\Litium.Accelerator.Mvc\\Routing\\PriceCalculatorDecorator.cs:rad 33
vid Litium.Foundation.Modules.ECommerce.Plugins.Orders.OrderRowFactory.GetProductCatalogEntities(ShoppingCartItemCarrier shoppingCartCarrier, Guid websiteId, Guid currencyId, Guid customerId, SecurityToken token, PriceCalculatorResult& listPriceResult, Guid countryId)
vid Litium.Foundation.Modules.ECommerce.Plugins.Orders.OrderRowFactory.Create(ShoppingCartItemCarrier shoppingCartRow, Guid websiteId, Guid currencyId, Guid customerId, Guid countryId, SecurityToken token)
vid Litium.Foundation.Modules.ECommerce.ShoppingCarts.Cart.SetProductUnitListPrices(OrderCarrier orderCarrier, SecurityToken token)
vid Litium.Foundation.Modules.ECommerce.ShoppingCarts.Cart.SetChannel(Channel channel, Country country, SecurityToken securityToken)
vid Litium.Accelerator.Mvc.Controllers.ControllerBase.Initialize(RequestContext requestContext) i Src\\Litium.Accelerator.Mvc\\Controllers\\ControllerBase.cs:rad 41
vid System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state)\r\n vid System.Web.Mvc.MvcHandler.<>c.<BeginProcessRequest>b__20_0(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState)
vid System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState)
vid System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout)
vid System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
vid Litium.Web.Mvc.Routing.MvcPageHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
vid System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
vid System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
vid System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
vid System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
vid System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
vid System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
vid System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
vid System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
vid System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
vid System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
vid System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
vid System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

```

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [March 23, 2021, 2:26pm UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/11 "2021-03-23T14:26:13Z")

</div>

Try using the `RouteRequestLookupInfoAccessor` instead, it has a property for the channel. `Initialize` is run prior to any filters I believe, so `RequestModel` won’t be set.

---

<div class="post-metadata">

**Author:** ![aram](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/aram/32/19_2.png) [@aram](https://forum.litium.com/u/aram)\
**Post date:** [March 23, 2021, 2:48pm UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/12 "2021-03-23T14:48:09Z")

</div>

Tested it with both `RouteRequestLookupInfoAccessor` and `CartAccessor` and both work fine, but I will go for `RouteRequestLookupInfoAccessor` feels kinda safer 😄

Thanks a lot for ur help, Nils!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [April 20, 2021, 2:48pm UTC](https://forum.litium.com/t/connect-pricelist-to-channel/1948/13 "2021-04-20T14:48:31Z")

</div>

Closed on April 20, 2021, 2:48pm UTC

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