Class SetCustomOrderDiscountAmount
- Namespace
- Dynamicweb.Ecommerce.Orders.Discounts
- Assembly
- Dynamicweb.Ecommerce.dll
public class SetCustomOrderDiscountAmount : DiscountExtenderBase, IDiscountExtenderCalculateOrderDiscount
- Inheritance
-
SetCustomOrderDiscountAmount
- Implements
- Inherited Members
Properties
OrderDiscount
[AddInParameter("The discount amount")]
[AddInDescription("Set this amount as the discount on the order.")]
[AddInParameterEditor(typeof(IntegerNumberParameterEditor), "")]
public double OrderDiscount { get; set; }
Property Value
Methods
DiscountValidForOrder(Order)
Determines if discount is valid for given order.
public override bool DiscountValidForOrder(Order order)
Parameters
order
Order- The order to conduct the check for.
Returns
- bool
true
if discount is valid for the specified order; otherwise,false
.
Examples
using Dynamicweb.Ecommerce.Orders;
using Dynamicweb.Ecommerce.Orders.Discounts;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Extensibility.Editors;
namespace Dynamicweb.Ecommerce.Examples.Orders.Discounts
{
/// <summary>
/// The example of an extender for order discounts
/// </summary>
public class FavoriteNameDiscountExtender : DiscountExtenderBase
{
[AddInParameter("Favorite name"), AddInDescription("Specify what a customer name should start with to get this discount"), AddInParameterEditor(typeof(TextParameterEditor), "")]
public string FavoriteName { get; set; }
/// <summary>
/// Constructor - sets the favorite name to Marta
/// </summary>
public FavoriteNameDiscountExtender()
{
FavoriteName = "Marta";
}
/// <summary>
/// If this extender is used for an order discount, it will be checked here
/// Checks if the name on the order starts with the specified name and returns true to apply the discount
/// </summary>
public override bool DiscountValidForOrder(Order order)
{
var valid = false;
if (!string.IsNullOrEmpty(FavoriteName) && !string.IsNullOrEmpty(order.CustomerName))
{
valid = order.CustomerName.StartsWith(FavoriteName, System.StringComparison.OrdinalIgnoreCase);
}
return valid;
}
}
}
DiscountValidForProduct(Product)
Determines if discount is valid for given product.
public override bool DiscountValidForProduct(Product product)
Parameters
product
Product- The product to conduct the check for.
Returns
- bool
true
if discount is valid for the specified product; otherwise,false
.
Examples
using Dynamicweb.Ecommerce.Products;
using Dynamicweb.Ecommerce.Orders.Discounts;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Extensibility.Editors;
namespace Dynamicweb.Ecommerce.Examples.Orders.Discounts
{
/// <summary>
/// The example of an extender for product discounts - if applied the discount will be valid for products with a price less than specified
/// </summary>
public class CheapProductsDiscountExtender : DiscountExtenderBase
{
[AddInParameter("Cheap price"), AddInDescription("Specify max price a product should have to get the discount"), AddInParameterEditor(typeof(IntegerNumberParameterEditor), "minValue=0;maxValue=1000;allowNegativeValues=false;localizeValues=true;")]
public int CheapPrice { get; set; }
/// <summary>
/// Constructor - sets the maximum price to 100
/// </summary>
public CheapProductsDiscountExtender()
{
CheapPrice = 100;
}
/// <summary>
/// If this extender is used for a product discount, it will be checked here
/// </summary>
public override bool DiscountValidForProduct(Product product)
{
return product.DefaultPrice <= CheapPrice;
}
}
}
GetDiscount(Order, PriceInfo)
Return the discount amount as a priceinfo that should be given to the passed order.
public PriceInfo GetDiscount(Order order, PriceInfo calculatedDiscount)
Parameters
order
Order- The order to calculate the discount for
calculatedDiscount
PriceInfo- The discount calculated by this discount instance
Returns
- PriceInfo
- The amount that is wanted to be given in discount
Remarks
Override or adjust the calculation made by the discount implementing this method.