Class FeeProvider
- Namespace
- Dynamicweb.Ecommerce.Orders
- Assembly
- Dynamicweb.Ecommerce.dll
The FeeProvider allows you to manipulate the shipping fee of an order in eCommerce using class inherited from Dynamicweb.eCommerce.Orders.FeeProvider.
public class FeeProvider
- Inheritance
-
FeeProvider
- Inherited Members
Examples
The following example demonstrates how to grant free shipping to customers who posts multiple orders within 24 hours. If the web shop can ship the items from the first and second order together, there is no need for the customer to be double-charged for shipping and handling. In cases where no previous orders have been submitted, the FeeProvider simply returns null which then will cause Dynamicweb eCommerce to ignore the FeeProvider when it sorts out the shipping fee.
using Dynamicweb.Data;
using Dynamicweb.Ecommerce.Orders;
using Dynamicweb.Ecommerce.Prices;
using System;
namespace Dynamicweb.Ecommerce.Examples.Orders;
/// <summary>
/// The following example demonstrates how to grant free shipping to customers
/// who posts multiple orders within 24 hours. If the web shop can ship the items
/// from the first and second order together, there is no need for the customer to be double-charged for shipping and handling.
/// In cases where no previous orders have been submitted, the FeeProvider
/// simply returns null which then will cause Dynamicweb eCommerce to ignore
/// the FeeProvider when it sorts out the shipping fee.
/// </summary>
class FeeProviderSample : FeeProvider
{
public override PriceRaw? FindFee(Order order)
{
PriceRaw? returnFee = null;
if (!string.IsNullOrEmpty(order.CustomerEmail))
{
// Using parameterized query to prevent SQL injection
string sqlQuery = "SELECT TOP 1 * FROM EcomOrders WHERE OrderCustomerEmail = {0} AND OrderDate >= {1} AND OrderComplete = {2}";
using (var reader = Database.CreateDataReader(CommandBuilder.Create(sqlQuery, order.CustomerEmail, DateTime.Now.AddDays(-1), true)))
{
if (reader.Read())
returnFee = new PriceRaw(0d, order.Currency);
}
}
return returnFee;
}
}
Methods
FindFee(Order)
Finds the fee for the order that should replace standard ones.
public virtual PriceRaw FindFee(Order order)
Parameters
orderOrderThe order.
Returns
- PriceRaw
Returns shipping fee for the specified order