Developer forum

Forum » Ecommerce - Standard features » Discount Calculations Incorrect

Discount Calculations Incorrect

George Jaros
Reply

While testing product discounts on a 9.16.6 site we discovered an issue with Discount calculations.

Wew set up a very basic 20% Discount and applied it to a Product Group.  When adding items from that group at multiple quantities to the cart the discounts initially display fine, but as soon as the order is placed the discounts still display correctly but are only applied once, not extended to the quantity of the item that was ordered.

Example:

  • An item costs $10 but has a 20% discount applied to its Product Group.
  • Add 10 of the item to the cart.  Product shows 10x$10 = $100, Discount shows 10x($2) = ($20), Order Total shows $80
  • Proceed through checkout, everything appears correct.  Line items, subtotal, and totals show correctly.
  • Complete order: Product is 10x$10 = $100, Discount shows 10x($2) = ($20), Order Total shows $98
    • The discount is only being applied one time, not ten, even though the line items show it applied ten times.

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi George

I will have QA look into it.

Please provide the following:

  1. Setup of your discount
  2. Your order discount settings (as displayed below)
  3. Screendumps of the checkout and receipt (including the template tags used to render the amounts in question in your template)

 
George Jaros
Reply
 
George Jaros
Reply
 
George Jaros
Reply

Here is the Order Discounts settings:

Discount configuration:

 

 

Discount shows correctly in the cart: 

Discount shows correctly through checkout.  This is the payment page.

 

However, as soon as the order is placed the discount goes from $6.40 to $0.64.  It's only applying once, not ten times.  This is even though the line item shows the correct amount.

 

Here's the order in the back end showing that the discount amount is only applied once ($0.64 instead of $6.40):

 

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi all,

I've checked the case using exact the same conditions and steps described above on Swift solution based on last DW9.6.11 and was not able to reproduce the issue using dummy payment as well as valid QuickPay checkout. IIS pool was recycled before it. Please, have a look at the video about my test.

BR, Oleg QA uic

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Could it be Live Integration, messing with the order in the last step? If you have Live Integration, did you check the XML requests and responses?

I have a similar case with Care where recurring orders are created with this issue (discount only applied to 1, not all products on a line), so it could be something in DW anyway...

Imar

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

And it might be changed by removing the checkbox "Add orderline discounts per quantity" setting

 
George Jaros
Reply

Thank you.  It turned out that this was due to the Live Integration being set to process carts on order completion.  It's a setting we need for clients paying invoices, but it's also affecting initial orders so our Integration Team is making some updates.

 
Roald Haahr
Reply

Hi all,

I faced a similar issue on a version 9.15.10 and solved it by rewriting the discount lines in the orders' request XML to always set the quantity of the discount lines to 1 and set the unit price to the total sum of the discount line.

If we have an order with order lines for ProductA and DiscountA

  • ProductA (Quantity = 10, UnitPrice = 10, TotalPrice = 100)
  • DiscountA (Quantity = 10, UnitPrice = -2, TotalPrice = -20)

With the code below it will be transformed to 

  • ProductA (Quantity = 10, UnitPrice = 10, TotalPrice = 100)
  • DiscountA (Quantity = 1, UnitPrice = -20, TotalPrice = -20)

 

Please be aware that I have removed chunks of code that I deemed irrelevant from the notification subscriber below, so I am not sure it will build, but I hope it can be of help anyway.

 

[Subscribe(Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.Order.OnAfterGenerateOrderXml)]
public class OrderAfterGenerateXml : NotificationSubscriber
{
    private static readonly Logger _logger = LogManager.GetLogger("OnAfterGenerateOrderXml");
 
    /// <summary>
    /// Call to invoke observer.
    /// </summary>
    /// <param name="notification">The notification.</param>
    /// <param name="args">The args.</param>
    public override void OnNotify(string notification, NotificationArgs args)
    {
        var myArgs = (Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.Order.OnAfterGenerateOrderXmlArgs)args;
        if (myArgs != null && myArgs.Document != null && myArgs.Order != null)
        {
            var document = myArgs.Document;
            var order = myArgs.Order;
 
            if (order.Complete)
            {
                XmlNode orderNode = document.SelectSingleNode("//item[@table='EcomOrders']");
               
                // fix discount lines
                FixDiscountLines(orderNode, document);
            }
        }
    }
 
    private void FixDiscountLines(XmlNode orderNode, XmlDocument document)
    {
        var orderLineNodes = orderNode.SelectNodes("//item[@table='EcomOrderLines']");
        foreach (XmlNode orderLineNode in orderLineNodes)
        {
            var orderLineTypeNode = orderLineNode.SelectSingleNode("column[@columnName='OrderLineTypeName']");
            var discountTypeNode = orderLineNode.SelectSingleNode("column[@columnName='OrderLineDiscountType']");
            if (orderLineTypeNode != null && discountTypeNode != null)
            {
                if (orderLineTypeNode.InnerText == "ProductDiscount" && discountTypeNode.InnerText == "Amount")
                {
                    var orderLineQuantityNode = orderLineNode.SelectSingleNode("column[@columnName='OrderLineQuantity']");
                    var orderLinePriceWithoutVatNode = orderLineNode.SelectSingleNode("column[@columnName='OrderLinePriceWithoutVat']");
                    var orderLineUnitPriceWithoutVatNode = orderLineNode.SelectSingleNode("column[@columnName='OrderLineUnitPriceWithoutVat']");
                    var orderLineDiscountValueNode = orderLineNode.SelectSingleNode("column[@columnName='OrderLineDiscountValue']");
                    if (orderLineQuantityNode != null && orderLineQuantityNode.InnerText != "1" && orderLinePriceWithoutVatNode != null && orderLineUnitPriceWithoutVatNode != null)
                    {
                        orderLineQuantityNode.InnerText = "1";
                        orderLineUnitPriceWithoutVatNode.InnerText = orderLinePriceWithoutVatNode.InnerText;
                        orderLineDiscountValueNode.InnerText = orderLinePriceWithoutVatNode.InnerText.Replace("-", "");
                    }
                }
            }
        }
    }
}

 

You must be logged in to post in the forum