Class PriceProvider
- Namespace
- Dynamicweb.Ecommerce.Prices
- Assembly
- Dynamicweb.Ecommerce.dll
Represents a price provider.
public class PriceProvider
- Inheritance
-
PriceProvider
- 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;
}
#if DW10
public override PriceRaw FindInformativePrice(PriceContext context, PriceProductSelection selection)
{
throw new System.NotImplementedException();
}
public override void PreparePrices(PriceContext context, IEnumerable<PriceProductSelection> selections)
{
throw new System.NotImplementedException();
}
#endif
}
}
Properties
HandlePricesExclusively
Property indicating whether this PriceProvider handles all prices.
public virtual bool HandlePricesExclusively { get; }
Property Value
- bool
- Boolean value indicating whether this PriceProvider handles all prices. DefaultPriceProvider will become disabled if
trueis returned.
Remarks
Methods
FindInformativePrice(PriceContext, PriceProductSelection)
Finds the informative price. Must be overriden.
public virtual PriceRaw FindInformativePrice(PriceContext context, PriceProductSelection selection)
Parameters
contextPriceContext- Context information.
selectionPriceProductSelection- Product information.
Returns
FindInformativePrice(Product, double, string, Currency, string, User)
Finds the informative price. Must be overriden.
[Obsolete("Use overload with PriceContext")]
public virtual PriceRaw FindInformativePrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user)
Parameters
productProduct- The product to find the price for.
quantitydouble- The quantity - usually 1, but if the product comes from an order or cart it can be higher. See remarks.
variantIdstring- The variant id of the current product.
currencyCurrency- The currency in which the price is required.
unitIdstring- The unit id of the product.
userUser- The user for whom the price is valid for.
Returns
FindInformativePrice(Product, double, string, Currency, string, User, string)
Finds the informative price. Must be overriden.
[Obsolete("Use overload with PriceContext")]
public virtual PriceRaw FindInformativePrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user, string shopId)
Parameters
productProduct- The product to find the price for.
quantitydouble- The quantity - usually 1, but if the product comes from an order or cart it can be higher. See remarks.
variantIdstring- The variant id of the current product.
currencyCurrency- The currency in which the price is required.
unitIdstring- The unit id of the product.
userUser- The user for whom the price is valid for.
shopIdstring- The shop id for whom the price is valid for.
Returns
FindInformativePrice(Product, double, string, Currency, string, User, string, StockLocation)
Finds the informative price. Must be overriden.
[Obsolete("Use overload with PriceContext")]
public virtual PriceRaw FindInformativePrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user, string shopId, StockLocation stockLocation)
Parameters
productProduct- The product to find the price for.
quantitydouble- The quantity - usually 1, but if the product comes from an order or cart it can be higher. See remarks.
variantIdstring- The variant id of the current product.
currencyCurrency- The currency in which the price is required.
unitIdstring- The unit id of the product.
userUser- The user for whom the price is valid for.
shopIdstring- The shop id for whom the price is valid for.
stockLocationStockLocation- The stock location.
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.
public virtual PriceRaw FindPrice(PriceContext context, PriceProductSelection selection)
Parameters
contextPriceContext- Context information.
selectionPriceProductSelection- 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
FindPrice(Product, double, string, Currency, string, User)
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.
[Obsolete("Use overload with PriceContext")]
public virtual PriceRaw FindPrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user)
Parameters
productProduct- The product to find the price for.
quantitydouble- The quantity - usually 1, but if the product comes from an order or cart it can be higher. See remarks.
variantIdstring- The variant id of the current product.
currencyCurrency- The currency in which the price is required.
unitIdstring- The unit id of the product.
userUser- The user for whom the price is valid for.
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
FindPrice(Product, double, string, Currency, string, User, double)
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.
[Obsolete("Use overload with PriceContext")]
public virtual PriceRaw FindPrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user, double quantityAllVariants)
Parameters
productProduct- The product to find the price for.
quantitydouble- The quantity - usually 1, but if the product comes from an order or cart it can be higher. See remarks.
variantIdstring- The variant id of the current product.
currencyCurrency- The currency in which the price is required.
unitIdstring- The unit id of the product.
userUser- The user for whom the price is valid for.
quantityAllVariantsdouble- The quantity of all variants.
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
FindPrice(Product, double, string, Currency, string, User, double, string)
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.
[Obsolete("Use overload with PriceContext")]
public virtual PriceRaw FindPrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user, double quantityAllVariants, string shopId)
Parameters
productProduct- The product to find the price for.
quantitydouble- The quantity - usually 1, but if the product comes from an order or cart it can be higher. See remarks.
variantIdstring- The variant id of the current product.
currencyCurrency- The currency in which the price is required.
unitIdstring- The unit id of the product.
userUser- The user for whom the price is valid for.
quantityAllVariantsdouble- The quantity of all variants.
shopIdstring- The shop id for whom the price is valid for.
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
FindPrice(Product, double, string, Currency, string, User, double, string, StockLocation)
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.
[Obsolete("Use overload with PriceContext")]
public virtual PriceRaw FindPrice(Product product, double quantity, string variantId, Currency currency, string unitId, User user, double quantityAllVariants, string shopId, StockLocation stockLocation)
Parameters
productProduct- The product to find the price for.
quantitydouble- The quantity - usually 1, but if the product comes from an order or cart it can be higher. See remarks.
variantIdstring- The variant id of the current product.
currencyCurrency- The currency in which the price is required.
unitIdstring- The unit id of the product.
userUser- The user for whom the price is valid for.
quantityAllVariantsdouble- The quantity of all variants.
shopIdstring- The shop id for whom the price is valid for.
stockLocationStockLocation- The current stock location.
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
PreparePrices(PriceContext, IEnumerable<PriceProductSelection>)
Prepares prices for a collection of products. Must be overriden.
public virtual void PreparePrices(PriceContext context, IEnumerable<PriceProductSelection> selections)
Parameters
contextPriceContext- Context information.
selectionsIEnumerable<PriceProductSelection>- 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 products 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.
PreparePrices(ProductCollection)
Prepares the prices for a list of products shown in the frontend - usually a product list or a list of related products, favorites etc. Must be overriden.
[Obsolete("Use overload with PriceContext")]
public virtual void PreparePrices(ProductCollection products)
Parameters
productsProductCollection- The products.
Remarks
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.
PreparePrices(Dictionary<Product, double>)
Prepares prices for a list of products coming from a cart or order context. Must be overriden.
[Obsolete("Use overload with PriceContext")]
public virtual void PreparePrices(Dictionary<Product, double> products)
Parameters
productsDictionary<Product, double>- The products 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 products price. This method is called once per instance (i.e. showing a list of orderlines in a cart or order) 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.
PreparePrices(IEnumerable<Product>)
Prepares the prices for a list of products shown in the frontend - usually a product list or a list of related products, favorites etc. Must be overriden.
[Obsolete("Use overload with PriceContext")]
public virtual void PreparePrices(IEnumerable<Product> products)
Parameters
productsIEnumerable<Product>- The products.
Remarks
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.