Class PriceProvider
- Namespace
- Dynamicweb.Ecommerce.Prices
- Assembly
- Dynamicweb.Ecommerce.dll
Represents a price provider used to overwrite or extend how Dynamicweb calculate prices by overriding Find
- Inheritance
-
Price
Provider
- Derived
- Inherited Members
Examples
using System.Collections.Generic;
using Dynamicweb.Ecommerce.Prices;
namespace Dynamicweb.Ecommerce.Examples.Prices
{
public class PriceProviderSample : PriceProvider
{
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;
}
}
}
Remarks
WARNING: Calling an instance of a cart inside Find
Properties
HandlePricesExclusively
Property indicating whether this Price
Property Value
- bool
Boolean value indicating whether this Price
Provider handles all prices. DefaultPrice will become disabled ifProvider true
is returned.
Remarks
Returning true
will cause Defaultfalse
.
Methods
FindInformativePrice(PriceContext, PriceProductSelection)
Finds the informative price. Must be overriden.
public virtual PriceRaw? FindInformativePrice(PriceContext context, PriceProductSelection selection)
Parameters
context
PriceContext Context information.
selection
PriceProduct Selection Product information.
Returns
FindPrice(PriceContext, PriceProductSelection)
Finds the price for a given product in a given context. Can be called to show the price of a product, show the price of a product for a specific user, unit etc. Must be overriden.
Parameters
context
PriceContext Context information.
selection
PriceProduct Selection Product information.
Returns
Remarks
This method is called in 2 contexts. For showing a product and a product added to a cart or order. If the call comes from an order object, it can have a quantity of 2 or more and can be used to return the unit price for a product that is cheaper if more than one is bought
FindQuantityPrices(PriceContext, Product)
Finds the quantity prices for a product in a given context.
public virtual IEnumerable<KeyValuePair<PriceQuantityInfo, PriceRaw>> FindQuantityPrices(PriceContext context, Product product)
Parameters
context
PriceContext Context information.
product
ProductProduct to find prices for.
Returns
- IEnumerable<Key
Value <PricePair Quantity , PriceInfo Raw >> All applicable quantity prices for the product.
PreparePrices(PriceContext, IEnumerable<PriceProductSelection>)
Prepares prices for a collection of products. Must be overriden.
public virtual void PreparePrices(PriceContext context, IEnumerable<PriceProductSelection> selections)
Parameters
context
PriceContext Context information.
selections
IEnumerable<PriceProduct >Selection Product selections with a list of products and their quantity in the current cart or order.
Remarks
This method is called before the actual use of each product price. 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.