Developer forum

Forum » Ecommerce - Standard features » SalesDiscount keeps getting deactivated

SalesDiscount keeps getting deactivated

Magni J. Hansen
Reply

I have created a sales discount. It works fine, but after some time, from hours to weeks, it gets automatically deactivated.
 
Why is that so ?


Replies

 
Merethe Nielsen
Reply
It's not normal behavior unless you have an expiration date/time for the sales discount or have custom modules that could make a conflict in the system.

We need more information about the solution where you experience the problem and what discount that has the problem.

Does it deactivate all sales discounts from time to time?

/Merethe
 
Magni J. Hansen
Reply

We only have 1 sales discount on this solution.

The discount is not set to deactive when you open the discount. The font color is gray when opening the discount page but after opening the discount and right away push save and close the font color is black and the discount works fine again.

The sales discount is a custom made discount. The discount code follows the standard DW code where i use the overridden method ProcessOrder in SalesDiscountProvider.

 
Magni J. Hansen
Reply

Here is my Sales Discount code:

using System;
using Dynamicweb.Extensibility;
using Dynamicweb.eCommerce.Orders;
using Dynamicweb.eCommerce.Orders.SalesDiscounts;
using Dynamicweb.Extensibility.Editors;
using Dynamicweb.eCommerce.Prices;
using Dynamicweb;
using System.Collections;
using System.Data;

namespace PostaSalesDiscount
{
    [AddInName("Økisavsláttur"), AddInDescription("Avsláttur bert galdandi fyri valt heimasíðu øki")]
    public class KioskDiscount : SalesDiscountProvider, IDropDownOptions
    {
        private int _areaid;
        private string _shopid;

        [AddInParameter("Condition"), AddInParameterEditor(typeof(MoreLessParameterEditor), "")]
        public string MoreLess { get; set; }

        [AddInParameter("Order buylimit"), AddInParameterEditor(typeof(TextParameterEditor), "")]
        public double OrderLimit { get; set; }

        [AddInParameter("AreaID"), AddInParameterEditor(typeof(Dynamicweb.Extensibility.Editors.DropDownParameterEditor), "")]
        public int AreaID
        {
            get { return _areaid; }
            set { _areaid = Base.ChkInteger(value); }
        }

        [AddInParameter("ShopID"), AddInParameterEditor(typeof(Dynamicweb.Extensibility.Editors.DropDownParameterEditor), "")]
        public string ShopID
        {
            get { return _shopid; }
            set { _shopid = value; }
        }

        Hashtable IDropDownOptions.GetOptions(string Name)
        {
            Hashtable htOptions = new Hashtable();
            switch (Name)
            {
                case "AreaID":
                    DataSet dsarea = Database.getDataSet("SELECT * FROM [Area] ORDER BY [AreaName] ASC");
                    if (dsarea != null)
                    {
                        if (dsarea.Tables[0].Rows.Count != 0)
                        {
                            foreach (DataRow dr in dsarea.Tables[0].Rows)
                            {
                                htOptions.Add(dr["AreaID"].ToString(), dr["AreaName"].ToString());
                            }
                        }
                    }
                    break;
                case "ShopID":
                    DataSet dsshop = Database.getDataSet("SELECT * FROM [EcomShops] ORDER BY [ShopName] ASC");
                    if (dsshop != null)
                    {
                        if (dsshop.Tables[0].Rows.Count != 0)
                        {
                            foreach (DataRow dr in dsshop.Tables[0].Rows)
                            {
                                htOptions.Add(dr["ShopID"].ToString(), dr["ShopName"].ToString());
                            }
                        }
                    }
                    break;
            }

            return htOptions;
        }

        public override void ProcessOrder(Dynamicweb.eCommerce.Orders.Order order)
        {
            Dynamicweb.Frontend.PageView pv = Dynamicweb.Frontend.PageView.Current();
            bool AmountValid = false;

            if (this.MoreLess == ">" && order.PriceBeforeFees.Price > this.OrderLimit && this.AreaID == pv.AreaID)
            {
                AmountValid = true;
            }
            else if (this.MoreLess == ">=" && order.PriceBeforeFees.Price >= this.OrderLimit && this.AreaID == pv.AreaID)
            {
                AmountValid = true;
            }
            else if (this.MoreLess == "==" && order.PriceBeforeFees.Price == this.OrderLimit && this.AreaID == pv.AreaID)
            {
                AmountValid = true;
            }
            else if (this.MoreLess == "<" && order.PriceBeforeFees.Price < this.OrderLimit && this.AreaID == pv.AreaID)
            {
                AmountValid = true;
            }
            else if (this.MoreLess == "<=" && order.PriceBeforeFees.Price <= this.OrderLimit && this.AreaID == pv.AreaID)
            {
                AmountValid = true;
            }

            if (AmountValid)
            {
                if (DiscountValue.Type == DiscountTypes.Product || DiscountValue.Type == DiscountTypes.Products)
                {
                    foreach (Dynamicweb.eCommerce.Products.Product product in order.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;

                        if (order.ShopID == this.ShopID) //make sure only specific items get the discount
                        {
                            order.OrderLines.Add(line, false);
                        }
                    }
                }
                else
                {
                    //Calculate discount
                    double discountPrice;

                    //How are we going to calculate this?
                    if (DiscountValue.Type == DiscountTypes.Percent)
                    {
                        discountPrice = (order.PriceBeforeFees.Price / 100) * DiscountValue.Amount;
                    }
                    else
                    {
                        discountPrice = DiscountValue.Amount;
                    }

                    //Get rawprice of the discount.
                    PriceRaw rawprice = new PriceRaw(discountPrice, Dynamicweb.eCommerce.Common.Application.DefaultCurrency);

                    //Convert to a calculated price
                    PriceCalculated CalcPrice = new 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
                    Dynamicweb.eCommerce.Orders.OrderLine line = new Dynamicweb.eCommerce.Orders.OrderLine();
                    line.Order = order;
                    line.Quantity = 1;
                    line.ProductName = this.DiscountName;
                    line.SetUnitPrice(discountPrice);
                    line.Type = Base.ChkString(Base.ChkNumber(OrderLine.OrderLineType.Discount));

                    if (order.ShopID == this.ShopID) //make sure only specific items get the discount
                    {
                        order.OrderLines.Add(line, false);
                    }
                }
            }
        }
    }
}
 

 
Magni J. Hansen
Reply

Here is before opening and after saving and closing screendumps

SnapShot_111109_160957.jpg SnapShot_111109_161055.jpg
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
Hi Magni

I have taken your code and created a SalesDiscount locally. As of yet I have been unable to reproduce the issue you're experiencing and there's nothing about the code that strikes me. I will continue to test but right now I have no concrete answers for you.

In the meantime -- I'd like to know some things about the solution. Like which version are you running? Are you using multiple languages? Does this issue only occur when certain products are given the discount?

- Jeppe
 
Magni J. Hansen
Reply
Solution is 19.2.3.2.
Solution is running two domains, posta.fo and stamps.fo. Posta.fo has one language and stamps.fo has five languages. So solution has 5 languages.
Sales discount is for posta.fo customers. The standard discount, running now, hits all customer. I have removed the custom build sales discount as custom build modules always are the primary target when debugging.
At this time we have not a certain pattern for when the discount is disabled. I will inform the client to look for specific products in orders around the sales discount is disabling.
 
Magni J. Hansen
Reply
Why is the sales discount in gray font color when active ? something must trigger this. 

 

You must be logged in to post in the forum