Table of Contents

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 FindPrice(PriceContext, PriceProductSelection)

public abstract class PriceProvider
Inheritance
PriceProvider
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 FindPrice(PriceContext, PriceProductSelection) i.e. by accessing Dynamicweb.Ecommerce.Common.Context.Cart, can cause the cart to be calculated and in order to do that, price providers are created and called. This will cause stack overflow exception and hence an application crash.

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 true is returned.

Remarks

Returning true will cause DefaultPriceProvider to become disabled. Default value is false.

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 PriceProductSelection

Product information.

Returns

PriceRaw

An instance of PriceRaw

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

context PriceContext

Context information.

selection PriceProductSelection

Product information.

Returns

PriceRaw

An instance of PriceRaw

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 Product

Product to find prices for.

Returns

IEnumerable<KeyValuePair<PriceQuantityInfo, PriceRaw>>

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<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 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.

To top