Table of Contents

Class PriceManager

Namespace
Dynamicweb.Ecommerce.Prices
Assembly
Dynamicweb.Ecommerce.dll

Represents a price manager. Provides methods to prepare and find prices for products.

public static class PriceManager
Inheritance
PriceManager
Inherited Members

Examples

using Dynamicweb.Ecommerce.Prices;
using Dynamicweb.Ecommerce.Products;

namespace Dynamicweb.Ecommerce.Examples.Prices;

class PriceManagerSample : PriceManager
{
    public PriceInfo GetCustomerPrice(PriceContext context, Product product)
    {
        PriceInfo customerPrice = GetPrice(context, product);

        //find your own price
        if (context.Customer is not null && context.Customer.CustomerNumber.StartsWith("abc"))
            customerPrice.Multiply(0.5);

        return customerPrice;
    }
}

Remarks

The PriceManager class is used to calculate and retrieve prices for products in various contexts. It supports operations such as getting prices for specific units and stock locations, calculating informative prices, and handling price caching.

Methods

FindPrice(PriceContext, PriceProductSelection, bool)

Finds the price for a given product selection within a specified context.

public static object FindPrice(PriceContext context, PriceProductSelection selection, bool isInformative)

Parameters

context PriceContext

The context in which the price is being requested.

selection PriceProductSelection

The product selection for which the price is being requested.

isInformative bool

Indicates whether the price is for informative purposes.

Returns

object

The price object for the given product selection.

Remarks

This method attempts to find the price using various price providers. It first checks for any exclusive price providers. If an exclusive provider is found, it uses that provider to find the price. If no exclusive providers are found, it falls back to checking all other providers except the default provider. If a price is found using any of these providers, it is returned. If no price is found using custom providers, the method finally falls back to using the default price provider.

FindPrice(PriceContext, Product, string, long, bool)

public static object FindPrice(PriceContext context, Product product, string unitId, long stockLocationId, bool isInformative)

Parameters

context PriceContext
product Product
unitId string
stockLocationId long
isInformative bool

Returns

object

GetInformativePrice(PriceContext, Product)

Gets the informative price for a given product.

public static PriceInfo GetInformativePrice(PriceContext context, Product product)

Parameters

context PriceContext

The price context which includes information such as currency, user, and other pricing rules.

product Product

The product for which the informative price is being retrieved.

Returns

PriceInfo

Returns the informative price of the specified product.

Remarks

This method calls the overloaded GetInformativePrice(PriceContext, Product, string, long) method,
passing the product's default unit ID and a stock location ID of 0.
The decision to use the product's default unit ID and a stock location ID of 0 is based on the assumption
that these are the most common parameters for retrieving an informative price.

GetInformativePrice(PriceContext, Product, string, long)

Gets the informative price for a given product.
This method calculates the price based on the product type and its components. It supports both simple products and complex products like BOM (Bill of Materials).

public static PriceInfo GetInformativePrice(PriceContext context, Product product, string unitId, long stockLocationId)

Parameters

context PriceContext

Price context which includes currency and other pricing details.

product Product

The product for which the informative price is to be calculated.

unitId string

The unit identifier for the product.

stockLocationId long

The stock location identifier where the product is stored.

Returns

PriceInfo

Returns the calculated informative price information for the specified product.

Remarks

The method follows these steps to determine the informative price:

  1. Check if the informative price is already cached. If so, return the cached price.
  2. Initialize a new PriceInfo object with the currency from the context.
  3. If the product is of type BOM (Bill of Materials) and its price type is calculated:
    a. Iterate through each item in the BOM.
    b. Retrieve the product for each item and create a PriceProductSelection.
    c. Find the informative price for each item.
    d. Multiply the price by the item's quantity and add it to the total price.
    e. If the product's price type includes a base price, find and add the base price.
  4. If the product is not of type BOM, find the informative price directly.
  5. Cache the calculated informative price and return it.

GetPrice(PriceContext, Product)

Gets the price for a given product, considering the default product unit if that is specified.

public static PriceInfo GetPrice(PriceContext context, Product product)

Parameters

context PriceContext

The price context which includes currency and other pricing details.

product Product

The product for which the price is to be calculated.

Returns

PriceInfo

Returns the calculated price information for the specified product.

Remarks

The method follows these steps to determine the price:

  1. Check if the price is already cached. If so, return the cached price.
  2. Initialize a new PriceInfo object with the currency from the context.
  3. If the product is of type BOM (Bill of Materials) and its price type is calculated: a. Iterate through each item in the BOM. b. Retrieve the product for each item and create a PriceProductSelection. c. Find the price for each item. d. Multiply the price by the item's quantity and add it to the total price. e. If the product's price type includes a base price, find and add the base price.
  4. If the product is not of type BOM, find the price directly.
  5. Cache the calculated price and return it.

GetPrice(PriceContext, Product, string, long)

Gets the price for a given product, considering the specified unit and stock location.

public static PriceInfo GetPrice(PriceContext context, Product product, string unitId, long stockLocationId)

Parameters

context PriceContext

The price context which includes currency and other pricing details.

product Product

The product for which the price is to be calculated.

unitId string

The unit identifier for the product.

stockLocationId long

The stock location identifier where the product is stored.

Returns

PriceInfo

Returns the calculated price information for the specified product.

Remarks

The method follows these steps to determine the price:

  1. Check if the price is already cached. If so, return the cached price.
  2. Initialize a new PriceInfo object with the currency from the context.
  3. If the product is of type BOM (Bill of Materials) and its price type is calculated: a. Iterate through each item in the BOM. b. Retrieve the product for each item and create a PriceProductSelection. c. Find the price for each item. d. Multiply the price by the item's quantity and add it to the total price. e. If the product's price type includes a base price, find and add the base price.
  4. If the product is not of type BOM, find the price directly.
  5. Cache the calculated price and return it.

GetQuantityPrices(PriceContext, Product)

Retrieves all quantity-based prices for a specified product within a given pricing context.

public static IEnumerable<KeyValuePair<PriceQuantityInfo, PriceInfo>> GetQuantityPrices(PriceContext context, Product product)

Parameters

context PriceContext

The pricing context, including currency and other relevant pricing details.

product Product

The product for which quantity-based prices are to be retrieved.

Returns

IEnumerable<KeyValuePair<PriceQuantityInfo, PriceInfo>>

An enumerable collection of key-value pairs where the key is a PriceQuantityInfo representing the quantity information, and the value is a PriceInfo representing the price information.

Remarks

This method performs the following steps to determine the quantity-based prices:

  1. Validates that the context and product parameters are not null.
  2. Initializes a list to store the resulting quantity prices.
  3. Retrieves the quantity prices using the FindQuantityPrices(PriceContext, Product) method.
  4. If the retrieved quantity prices are of type PriceInfo: a. Iterates through each quantity price. b. Sets the price source to CustomProvider if it has a value. c. Adds the quantity price to the result list.
  5. If the retrieved quantity prices are of type PriceRaw: a. Iterates through each quantity price. b. Sets the price source to CustomProvider if it has a value. c. Calculates the price using the CalculatePrice(PriceContext, PriceRaw, Product, bool) method. d. Adds the calculated price to the result list.
  6. Returns the result list containing the quantity-based prices.

PreparePrices(PriceContext, IEnumerable<PriceProductSelection>)

Prepares prices and retrieves them from database for all products in the product selections.

public static void PreparePrices(PriceContext context, IEnumerable<PriceProductSelection> selections)

Parameters

context PriceContext

The price context in which the prices are being prepared.

selections IEnumerable<PriceProductSelection>

The product selections for which the prices are being prepared.

Remarks

This method prepares prices using various price providers. It first checks for any exclusive price providers. If an exclusive provider is found, it uses that provider to prepare the prices and stops further processing. If no exclusive providers are found, it falls back to preparing prices using the default provider first, followed by any other custom providers.

PreparePrices(PriceContext, IEnumerable<Product>)

Prepares the prices for a collection of products.

public static void PreparePrices(PriceContext context, IEnumerable<Product> products)

Parameters

context PriceContext

The price context which contains information about the pricing strategy and other relevant data.

products IEnumerable<Product>

The collection of products for which prices need to be prepared.

Remarks

This method initializes the price preparation process for a given set of products. It calls an overloaded method with a default stock location identifier of 0.

PreparePrices(PriceContext, IEnumerable<Product>, long)

Prepares the prices for a collection of products with a specified stock location identifier.

public static void PreparePrices(PriceContext context, IEnumerable<Product> products, long stockLocationId)

Parameters

context PriceContext

The price context which contains information about the pricing strategy and other relevant data.

products IEnumerable<Product>

The collection of products for which prices need to be prepared.

stockLocationId long

The identifier for the stock location to be considered while preparing prices.

Remarks

This method prepares the prices by creating a list of PriceProductSelection objects, each representing a product and its associated stock location. The method then delegates the actual price preparation to another overloaded method that accepts a collection of PriceProductSelection objects.

To top