Discount Names in Orders

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I think you could use 0.0000 for your tracking discounts and change your export to only show it if there is a name.  Then you don't have to worry about the math.

order.DiscountUsageHistory.Count() will also tell you how many discounts are on the order.
12 years ago
Well, the following seems to work ok and doesn't involve any math or any discount value, but seems a tad kludgy:


    try
    {
   worksheet.Cells[row, col].Value = _discountService.GetDiscountById(order.DiscountUsageHistory.FirstOrDefault().DiscountId).Name.ToString();
        col++;
      }
      catch
      {
       worksheet.Cells[row, col].Value = "None";
        col++;
       }



Can I assume that an entry is always made to DiscountUsageHistory if a customer enters a discount code, even if the discount amount is 0.0000? The above code depends on just that, it seems to me.
12 years ago
I would assume so.  One thing to note is you should avoid relying on try/catch for logic operations.  It will probably work as you have it but throwing exceptions is expensive and should be reserved for things that are truly exceptional (database unavailable, unexpected error, etc).

I would rewrite it like this:


string discountName = "None";
if(order.DiscountUsageHistory.Count > 0)
{
   discountName = order.DiscountUsageHistory.First().Discount.Name;
}

worksheet.Cells[row, col].Value = discountName;
col++;
12 years ago
Thanks Andy, and also Jacob,

for all your help.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.