Developer forum

Forum » Development » Building Custom PriceProvider with multiple quantity based prices?

Building Custom PriceProvider with multiple quantity based prices?

Evaldas Raisutis
Evaldas Raisutis
Reply

We are considering to build a custom PriceProvider which would plug into a ERP-type-of gateway. One of the requirements is that we can provide multiple prices for a given product (per user context).

1. When implementing a custom PriceProvider, I am able to override Product.Prices PriceCollection, allowing me to set any list of prices I want. Is this correct way to do this?

2. What is PreparePrices(Dictionary<Product, double> products) overload used for? As I understand it's a "high level" method where we would implement price caching for a product collection. What does the double stand for? Does it represent a dictionary of product and it's price? If so, we would also modify Product.Prices for multiple prices here? This method does not seem to take logged in user into account though?

3. What's the difference between PreparePrices(Dictionary<Product, double> products) and PreparePrices(ProductCollection products) overloads? Are they called from different contexts, and if so, what are they?

4. One of the FindPrice overloads accepts additional parameter of "double quantityAllVariants", what does that mean and how it should be utilized? 

5. None of PreparePrices overloads takes user context as parameter - does this mean the prices here should not be loaded per user context, or do we need to fetch it from elsewhere? Solution we are building will consist only of user specific prices.

I am sorry but I find api documentation on this a bit lacking. http://doc.dynamicweb.com/api/html/46b0e0a8-5a77-3712-038d-c7fbc4e96346.htm

 

Thank you in advance,
Evaldas Raisutis


Replies

 
Evaldas Raisutis
Evaldas Raisutis
Reply

6. It seems that PreparePrices is not supposed to modify the collection, just prepare price cache. However, I can't find a way to populate DW price cache. Of course I could cache them elsewhere, and populate Product.Prices when FindPrice is called, but that seems slightly out of place? Product parameter in FindPrice seems to already have Prices populated from the database, so even though I am implementing a PriceProvider, it seems that there is still some default behavior going on, which is unnessarary. 

 
Nicolai Pedersen
Reply

Hi Evaldas

Granted - the docs are a little vauge. I've updated the docs and it will be out tomorrow when rebuild.

@2+3+5

PreparePrices(Dictionary<Product, double> products) is called from orders and carts. and is basically coming from a list of orderlines. Product is of course the product, double is the quantity in the cart.

PreparePrices(ProductCollection products)
This method is called before the actual use of each products price. This method is called once per instance (i.e. showing a list of products) where FindPrice is called once for each product in the list. Use this method to find all the prices needed in the upcoming FindPrice calls. This method can be used to retrieve i.e. 30 prices from an ERP system and saved into a cache that is later used by FindPrice.

There is no user context called here - you have to check that yourself on User.Current

@4
It is called from an order or cart. it handles situations where you have the same product in different quantities or variants. If I have a blue and a red of the same t-shirt - do I then have 1 of each or I have 2 of the t-shirt and get quantity pricing? That is a method that is there to handle that kind of scenarios. It is also used in BOM/Parts list calculations. Usually you do not need to handle anything in this method.

@6:
You just cache it in a static, cache object or session. Depends on the implementation what makes sense. You should not overwrite the product.prices property

And your question:
Provide multiple prices per product: If you want to display multiple prices, whatever that means, i.e. 1 cost 100 each, 2 costs 98 each etc. you could integrate to the price matrix. Or you could create a product template extender and render a loop of prices in whatever logic you need. Then in your priceprovider you calculate the right price - i.e. if it is supporting quantity pricing, findprice for 1 product is 100, findprice for 2 is 98. So you get 2 logics - a rendering logic just showing what will happen once you add products to the cart.

Hope this clarifies!

Happy coding, Nicolai

 
Evaldas Raisutis
Evaldas Raisutis
Reply

Hi Nicolai,

Thanks for your Reply. Makes sense, thanks for the explanation. 

Regarding your last comment - we are trying to avoid integration to price matrix, because we would have to actively maintain collection of about 14mil prices (and growing). However, the option with template extender sounds like the way to go for showing different available prices. We would cache prices per product per user when available, and then output it in template directly from the cache. In doing so we would decouple rendering logic and fetching price, as you suggested. Sounds fine :)

Thanks!

 

You must be logged in to post in the forum