Posted on 07/03/2023 16:51:33
I think you can easily do that with a price provider:
This is just an example with some random checks for quantity, user customer number and how to find a custom product field.
So in this one, you can locate the factor and add that to the price - part of the example.
The priceprovider should not handle quantity - that will be handled by the cart - so this one needs to return the correct unitprice - but unit price can vary by the qty in cart, hence the example of that.
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);
var someVariable = selection.Product.ProductFieldValues["someCustomField"].Value;
//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;
}
}
}