Cannot apply discount for an order

GTEK IT DEV Team asked on October 3, 2019 05:01

I have the following code snippet:

// Creates a new order object and sets its properties
OrderInfo newOrder = new OrderInfo
{
    OrderInvoiceNumber = StringUltils.RandomString(15, false),
    OrderTotalPrice = product.SKUPrice - totalDiscount,
    OrderGrandTotal = product.SKUPrice - totalDiscount,
    OrderTotalTax = 0,
    OrderDate = DateTime.Now,
    OrderStatusID = orderStatus.StatusID,
    OrderCustomerID = customerInfo.CustomerID,
    OrderSiteID = SiteContext.CurrentSiteID,
    OrderCurrencyID = currency.CurrencyID,
    OrderGrandTotalInMainCurrency = product.SKUPrice - totalDiscount,
    OrderCulture = currentUser.PreferredCultureCode
};


// Saves the order to the database
OrderInfoProvider.SetOrderInfo(newOrder);

// Creates a new order item object and sets its properties
OrderItemInfo newItem = new OrderItemInfo
{
    OrderItemSKUName = product.SKUNumber,
    OrderItemOrderID = newOrder.OrderID,
    OrderItemSKUID = product.SKUID,
    OrderItemUnitPrice = product.SKUPrice,
    OrderItemUnitCount = 1,
    OrderItemTotalPrice = product.SKUPrice - totalDiscount
};

// Saves the order item object to the database
OrderItemInfoProvider.SetOrderItemInfo(newItem);

But when this order saved to the Orders application. The total price of the order still is the original price. The total price just change to correct value when i click Update button in Items tab of the order. What am i wrong?

Recent Answers


Peter Mogilnitski answered on October 3, 2019 18:37

You are trying to hard-code the discount in the order. I think you should create DiscountInfo and connect it to your order. System should automatically calculate the discount if it is applicable.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.