Dynamicweb.eCommerce.Orders.SalesDiscounts Namespace : SalesDiscountProvider Class |
'Declaration
Public Class SalesDiscountProvider Inherits Dynamicweb.Extensibility.ConfigurableAddIn
public class SalesDiscountProvider : Dynamicweb.Extensibility.ConfigurableAddIn
[AddInName("Total price discount")] [AddInDescription("If the total sum of the products purchased on an order is equal or bigger that the specified amount a discount will be triggered.") ] public class TotalSalesPriceDiscount : SalesDiscountProvider { #region Fields private string _MoreLess = ""; private double _BuyLimit = 1000.0; private DiscountValueHandler _DiscountValue = new DiscountValueHandler(); #endregion #region Properties [AddInParameter("Condition"), AddInParameterEditor(typeof(Editors.MoreLessParameterEditor), "")] public string MoreLess { get { return _MoreLess; } set { _MoreLess = value; } } [AddInParameter("Order buylimit"), AddInParameterEditor(typeof(Editors.TextParameterEditor), "")] public double BuyLimit { get { return _BuyLimit; } set { _BuyLimit = value; } } [AddInParameter("Discount"), AddInParameterEditor(typeof(Editors.DiscountValueEditor), "")] public string DiscountValue { get { if (_DiscountValue == null) _DiscountValue = new DiscountValueHandler(); return _DiscountValue.Value; } set { if (_DiscountValue == null) _DiscountValue = new DiscountValueHandler(); _DiscountValue.Value = value; } } #endregion #region Methods public override void ProcessOrder(Order _order) { bool AmountValid = false; if (this.MoreLess == ">" && _order.PriceBeforeFees.Price > this.BuyLimit) AmountValid = true; else if (this.MoreLess == ">=" && _order.PriceBeforeFees.Price >= this.BuyLimit) AmountValid = true; else if (this.MoreLess == "==" && _order.PriceBeforeFees.Price == this.BuyLimit) AmountValid = true; else if (this.MoreLess == "<" && _order.PriceBeforeFees.Price < this.BuyLimit) AmountValid = true; else if (this.MoreLess == "<=" && _order.PriceBeforeFees.Price <= this.BuyLimit) AmountValid = true; if (AmountValid == true) { if (this._DiscountValue.Type == DiscountTypes.Product || this._DiscountValue.Type == DiscountTypes.Products) { foreach (Products.Product product in this._DiscountValue.Products) { OrderLine line = new OrderLine(); line.OrderID = _order.ID; line.Order = _order; line.ProductID = product.ID; line.ProductVariantID = product.VariantID; line.Quantity = 1; line.Modified = DateTime.Now; line.ProductName = product.Name; line.ProductNumber = product.Number; line.Reference = "Default.aspx?ID=" + PageId + "&ProductID=" + product.ID + "&VariantID=" + product.VariantID; line.Type = base.ChkString(base.ChkNumber(OrderLine.OrderLineType.Discount)); line.PageID = PageId; line.Product = product; _order.OrderLines.Add(line, false); } } else { // Calculate discount double discountPrice = 0; // How are we going to calculate this? if (this._DiscountValue.Type == DiscountTypes.Percent) { discountPrice = (_order.PriceBeforeFees.Price / 100) * this._DiscountValue.Amount; } else if (this._DiscountValue.Type == DiscountTypes.FixedAmount) { discountPrice = this._DiscountValue.Amount; } // Get rawprice of the discount. PriceRaw rawprice = new PriceRaw(discountPrice, Dynamicweb.eCommerce.Common.Application.DefaultCurrency); // Convert to a calculated price Prices.PriceCalculated CalcPrice = new Prices.PriceCalculated(rawprice); CalcPrice.PriceWithoutVAT = CalcPrice.PriceWithVAT; CalcPrice.VATPercent = 0; CalcPrice.VAT = 0; // We need a negative value discountPrice = CalcPrice.Price - (CalcPrice.Price * 2); // Add a new order line OrderLine line = new OrderLine(); line.Order = _order; line.Quantity = 1; line.ProductName = this.DiscountName; line.SetUnitPrice(discountPrice); line.Type = base.ChkString(base.ChkNumber(OrderLine.OrderLineType.Discount)); // Insert orderline _order.OrderLines.Add(line, false); } } } #endregion }
System.Object
Dynamicweb.Extensibility.ConfigurableAddIn
Dynamicweb.eCommerce.Orders.SalesDiscounts.SalesDiscountProvider
Dynamicweb.eCommerce.Orders.SalesDiscounts.DateTimeDiscount
Dynamicweb.eCommerce.Orders.SalesDiscounts.OrderFieldDiscountUniqueVoucher
Dynamicweb.eCommerce.Orders.SalesDiscounts.ProductDiscount
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2