Click or drag to resize

ProductProviderBase Class

Default implementation of a product provider to get prices and other info for products from the ERP. Inherit this class and override one or more of its methods to alter the behavior.
Inheritance Hierarchy
SystemObject
  Dynamicweb.Ecommerce.LiveIntegration.ProductsProductProviderBase

Namespace:  Dynamicweb.Ecommerce.LiveIntegration.Products
Assembly:  Dynamicweb.Ecommerce.LiveIntegration (in Dynamicweb.Ecommerce.LiveIntegration.dll) Version: 3.0.1
Syntax
public class ProductProviderBase

The ProductProviderBase type exposes the following members.

Constructors
  NameDescription
Public methodProductProviderBase
Initializes a new instance of the ProductProviderBase class
Top
Methods
  NameDescription
Public methodExtractPrices
Extracts the prices.
Public methodFillProductValues
Fills the product values.
Public methodCode exampleGetPrice
Gets the price.
Public methodGetProductFromVariantComboId
Gets the product from variant combo identifier.
Public methodGetProductIdentifier(Product)
Creates a unique product identifier by concatenating the product ID or number (depends on the CalculatePriceUsingProductNumber setting), the variant ID and the language ID. Override to build up your own unique identifier.
Public methodGetProductIdentifier(Product, String)
Creates a unique product identifier by concatenating the product ID or number (depends on the CalculatePriceUsingProductNumber setting), the variant ID and the language ID. Override to build up your own unique identifier.
Public methodGetProductPrices
Gets the product prices list.
Public methodIsLivePriceEnabledForProduct
Checks if the product is enabled for the live prices requests. Override this method if you want to skip some products from being looked up in the ERP.
Top
Examples
C#
using Dynamicweb.Ecommerce.Integration;
using Dynamicweb.Ecommerce.Products;

namespace Dynamicweb.Ecommerce.LiveIntegration.Examples
{
    /// <summary>
    /// Class CustomProductProvider.
    /// </summary>
    /// <seealso cref="Products.ProductProviderBase" />
    public class CustomProductProvider : Products.ProductProviderBase
    {
        /// <summary>
        /// Gets the product identifier.
        /// </summary>
        /// <param name="product">The product.</param>
        /// <returns>System.String.</returns>
        public override string GetProductIdentifier(Product product)
        {
            return GetProductIdentifier(product, null);
        }

        /// <summary>
        /// Gets the product identifier.
        /// </summary>
        /// <param name="product">The product.</param>
        /// <param name="unitId">The product unit Id.</param>
        /// <returns>System.String.</returns>
        public override string GetProductIdentifier(Product product, string unitId)
        {
            string unit = string.IsNullOrEmpty(unitId) ? string.Empty : $"-{unitId}";
            return $"{product.Id}-{product.VariantId}-{product.LanguageId}-{product.Number}{unit}";
        }

        /// <summary>
        /// Gets the price.
        /// </summary>
        /// <param name="product">The product.</param>
        /// <param name="quantity">The quantity.</param>
        /// <returns>System.Nullable&lt;System.Double&gt;.</returns>
        public override double? GetPrice(ProductInfo product, double quantity)
        {
            // Example: if we have a price per kilogram - we need to multiply it by quantity
            double unitPrice;
            if(double.TryParse(product["TotalPrice"].ToString(), out unitPrice))
            {
                return unitPrice * quantity;
            }
            else
            {
                return base.GetPrice(product, quantity);
            }            
        }
    }
}
See Also