Click or drag to resize

ProductProviderBaseGetPrice Method

Gets the price.

Namespace:  Dynamicweb.Ecommerce.LiveIntegration.Products
Assembly:  Dynamicweb.Ecommerce.LiveIntegration (in Dynamicweb.Ecommerce.LiveIntegration.dll) Version: 3.0.1
Syntax
public virtual Nullable<double> GetPrice(
	ProductInfo product,
	double quantity
)

Parameters

product
Type: Dynamicweb.Ecommerce.IntegrationProductInfo
The product.
quantity
Type: SystemDouble
The quantity.

Return Value

Type: NullableDouble
System.Nullable<System.Double>.
Exceptions
ExceptionCondition
ArgumentNullExceptionproduct
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