Developer forum

Forum » Development » Getting Default Price in Price Provider

Getting Default Price in Price Provider

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I have a PriceProvider that calls out to an ERP to get a price for a product. When the ERP does not have a price, I would like to default to the standard Dynamicweb price. However, based on the user, I need to add some markup to that price. What's the recommended scenario? Can I use base.FindPrice to find Dynamicweb's price and add the markup. Would that work when you have multiple price providers configued?
 

Imar

 


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Imar,

It can be done, but it's a little involved. I would, however, not recommend that you call into base.FindPrice as this method will simply return null. Instead you should call the relevant FindPrice overload in PriceManager while maintaining a variable that you initiated the call. That way your provider returns null when it's asked for a price in your call stack.

Something like this:

var itemsEntryName = "PriceCallInvokedFromMe";

// Check to see whether this price request is initiated from this provider
if (HttpContext.Current.Items.Contains(itemsEntryName))
	return null; // Secondary price calculation initiated from this price provider -- returning null to go to the next provider

HttpContext.Current.Items[itemsEntryName] = true;

// Get price from another price provider -- chain always ends with system price if no other price is found
var price = Dynamicweb.eCommerce.Prices.PriceManager.FindPrice(product); // Maybe one of the other overloads is better?

// TODO: Manipulate the price according to the requirements

// Remember to remove the tracking variable from the Items collection in case other price calculations are needed in this HTTP request
HttpContext.Current.Items.Remove(itemsEntryName);

// Return the newly found and manipulated price as if it were my own
return price;

- Jeppe

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

That sounds perfect. Thanks, I'll give it a try!

Imar

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Jeppe,

I implemented it and it works great. I noticed that FindPrice returns an object. In my testing I am seeing instances of PriceRaw being returned. Is it safe to assume I am always get a PriceRaw or a descendant or could I receive other types as well?

Imar

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

You cannot not assume that it's always a PriceRaw object you get. It depends on the PriceProvider that gives you the price. If it's a PriceProvider that implements the ISupportPriceInfo interface then you get a PriceInfo object instead. This is something you need to handle yourself, unfortunately.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

OK, great, thanks for that infol. I am doing a soft cast to a PriceRaw and handle null values so I should be fine. It's currently the only price provider so I am not expecting any issues.

Imar

 

You must be logged in to post in the forum