Developer forum

Forum » Development » Determine sort order for price providers

Determine sort order for price providers

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I have a site that uses multiple integrations and price providers. In one scenario, I have a standard Live Integration to BC. When that returns a price, it should be used. Otherwise, it needs to run through my own price provider.

How can I guarantee the order of providers? In PriceManager.CheckProviderTypesInCache I can see how the providers are retrieved but not sorted, which I believe means they come in unsorted.

foreach (Type addIn in AddInManager.GetAddInClasses(typeof(PriceProvider)))
{
    if (!ReferenceEquals(addIn, typeof(DefaultPriceProvider)))
    {
        priceProviderTypes.Add(addIn);
    }
}

Then when they are used, in PriceManager.FindPrice, they are simply looped over until one returns a price. Is there a possibility to force the order and determine when my own provider runs? In other extensibility type we have something like Rank but I am not seeing that here.

Thanks!

Imar

 

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Imar

Currently you cannot - and it was originally not designed for multpile price providers. The most natural solution would be to introduce the AddInOrderAttribute that we use elsewhere.

What you could do, is to let your own PriceProvider return true on the HandlePricesExclusively property which would essentially disable the other providers.

The inside your FindPrice you will do the logic as to when to ask the other providers explicitly - simply by creating instances of them and ask them for a price and return it if:

public override PriceRaw FindPrice(PriceContext context, PriceProductSelection selection)

{

 // Get the price from the DefaultPriceProvider

 DefaultPriceProvider defaultProvider = new DefaultPriceProvider();

 PriceRaw customPrice = defaultProvider.FindPrice(context, selection);


 //find your own price

 if (context.Customer != null && context.Customer.CustomerNumber.StartsWith("abc"))

 {

 customPrice.Price *= .90;

 return customPrice;

 }

 else if (selection.Quantity > 1)

 {

 customPrice.Price *= .95;

 return customPrice;

 }


 return customPrice;

}
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Nicolai,

That's fine for the DefaultPriceProvider as you can simply new one up. For others, like LI price providers this won't be so easy as there could be many different sites (10-15 likely) that each have their own connection to the ERP with additional filters for Site, Shop and what not. The DefaultPriceProvider wouldn't handle this, would it?

>>  The most natural solution would be to introduce the AddInOrderAttribute that we use elsewhere.

Agreed!

Imar

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Yeah, you can new LI PP and just proxy parameters through to that and the default pricer provider as well. The logic on which connection should be used is inside the LI provider.

 

You must be logged in to post in the forum