Posted on 20/05/2022 16:18:20
Using a price provider
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"))
{
//User is logged in
//find the product field:
var product = Services.Products.GetProductById(selection.ProductId, selection.VariantId, true);
var price = Services.Products.GetProductFieldValue(product, "CustomPrice");
//parse the price which is an object to a double and set the price below
customPrice.Price *= .90;
return customPrice;
}
else if (selection.Quantity > 1)
{
customPrice.Price *= .95;
return customPrice;
}
return customPrice;
}
}
}