Free Shipping Discounts

Jay Asbury asked on July 29, 2024 20:53

Is there a 100% reliable way to retrieve the free shipping discount info that was applied?

I know I can use coupon codes and query against that but if coupon codes are not used, that goes out the window. I do not see an order discount or similar discount api access I can do that will give me x discount sku was applied which gave the OrderInfo object a free shipping. I can compare the would be x shipping and the TotalShipping to see that free shipping was done but I can't find X discount was applied to the order info using the api.

Recent Answers


Jay Asbury answered on July 29, 2024 21:12

I did find https://docs.kentico.com/13/e-commerce-features/customizing-on-line-stores/customizing-discounts but I don't want to recalculate an OrderInfo object. I want to get the discount applied at time of calc originally. I am starting with this code.

/// <summary>
/// Gets all the different discounts from the OrderInfo object and returns a summary of the discounts without any currency conversion.
/// </summary>
/// <param name="order"><see cref="OrderInfo"/> object to get discounts from</param>
/// <param name="includeGiftCards">Set to true to also calculate discounts from any gift cards as discounts instead of treating as payment after the total.</param>
/// <returns><see cref="Decimal"/> total discounts added </returns>
/// <remarks>See https://devnet.kentico.com/questions/k13-orderinfo-get-total-discounts</remarks>
public static ValuesSummary GetAllDiscounts(this OrderInfo order, bool includeGiftCards = false)
{
    var orderDiscountSummary = new ValuesSummary(order.OrderDiscounts);

    var itemTotalDiscounts = new ValuesSummary();
    foreach (var orderItem in OrderItemInfoProvider.GetOrderItems(order.OrderID))
    {
        var productDiscountsSummary = new ValuesSummary(orderItem.OrderItemProductDiscounts);
        foreach (var productDiscount in productDiscountsSummary)
        {
            productDiscount.Value *= orderItem.OrderItemUnitCount;
        }
        itemTotalDiscounts.Merge(productDiscountsSummary);


        var itemDiscountsSummary = new ValuesSummary(orderItem.OrderItemDiscountSummary);
        itemTotalDiscounts.Merge(itemDiscountsSummary);
    }
    orderDiscountSummary.Merge(itemTotalDiscounts);

    if (includeGiftCards)
    {
        var giftCardsSumary = new ValuesSummary(order.OrderOtherPayments);
        orderDiscountSummary.Merge(giftCardsSumary);
    }
    return orderDiscountSummary;
}

}

0 votesVote for this answer Mark as a Correct answer

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