Group coupon in the print invoice
-
- Ensign (ENS)
- Posts: 6
- Joined: Wed May 16, 2012 9:18 pm
Group coupon in the print invoice
Is there a way to group coupon instead have the coupon per item? I found one patch for the checkout page where group coupon viewtopic.php?f=42&t=15239 is there a path for print invoice?
-
- Ensign (ENS)
- Posts: 6
- Joined: Wed May 16, 2012 9:18 pm
Re: Group coupon in the print invoice
Any one please help
Re: Group coupon in the print invoice
I just did this. If this helps anyone else out. Around line 99 in the invoice.aspx.cs file (found in ~admin/orders/print)
Look for this...
change it to this...
This removes it from the showing up below each item. It will still shown at the bottom subtotal table.
Look for this...
Code: Select all
private OrderItemType[] displayItemTypes = { OrderItemType.Product, OrderItemType.Discount,
OrderItemType.Coupon, OrderItemType.Shipping, OrderItemType.Handling, OrderItemType.GiftWrap,
OrderItemType.Charge, OrderItemType.Credit, OrderItemType.GiftCertificate, OrderItemType.Tax};
protected OrderItemCollection GetItems(object dataItem)
Code: Select all
private OrderItemType[] displayItemTypes = { OrderItemType.Product, OrderItemType.Discount,
OrderItemType.Shipping, OrderItemType.Handling, OrderItemType.GiftWrap,
OrderItemType.Charge, OrderItemType.Credit, OrderItemType.GiftCertificate, OrderItemType.Tax};
protected OrderItemCollection GetItems(object dataItem)
-
- Ensign (ENS)
- Posts: 6
- Joined: Wed May 16, 2012 9:18 pm
Re: Group coupon in the print invoice
Thank you crazyjoe but I was able to group all coupon in the invoice and not removing it in the order items.
Hope this will help anyone
Code: Select all
private OrderItemType[] displayItemTypes = { OrderItemType.Product, OrderItemType.Discount,
OrderItemType.Coupon, OrderItemType.Shipping, OrderItemType.Handling, OrderItemType.GiftWrap,
OrderItemType.Charge, OrderItemType.Credit, OrderItemType.GiftCertificate, OrderItemType.Tax};
Dictionary<string, decimal> ctr = new Dictionary<string, decimal>();
Dictionary<string, decimal> i = new Dictionary<string, decimal>();
protected OrderItemCollection GetItems(object dataItem)
{
Order order = (Order)dataItem;
OrderItemCollection items = new OrderItemCollection();
//REMOVE VAT ENTRIES
Dictionary<string, decimal> couponTotals = new Dictionary<string, decimal>();
Dictionary<string, decimal> couponCounter = new Dictionary<string, decimal>();
foreach (OrderItem item in order.Items)
{
if (item.OrderItemType == OrderItemType.Coupon)
{
if (couponCounter.ContainsKey(item.Name))
{
ctr[item.Name]++;
couponCounter[item.Name] = ctr[item.Name];
}
else
{
ctr[item.Name] = 0;
couponCounter[item.Name] = ctr[item.Name];
}
}
}
foreach (OrderItem item in order.Items)
{
if (Array.IndexOf(displayItemTypes, item.OrderItemType) >= 0 && (item.OrderItemType != OrderItemType.Tax))
{
if (item.OrderItemType == OrderItemType.Product && item.IsChildItem)
{
// WHETHER THE CHILD ITEM DISPLAYS DEPENDS ON THE ROOT
OrderItem rootItem = item.GetParentItem(true);
if (rootItem.Product != null && rootItem.ItemizeChildProducts)
{
// ITEMIZED DISPLAY ENABLED, SHOW THIS CHILD ITEM
items.Add(item);
}
}
else if (item.OrderItemType == OrderItemType.Coupon)
{
if (couponTotals.ContainsKey(item.Name)) couponTotals[item.Name] += (decimal)item.ExtendedPrice;
else couponTotals[item.Name] = (decimal)item.ExtendedPrice;
if (!i.ContainsKey(item.Name))
i[item.Name] = 0;
if(i[item.Name] > couponCounter[item.Name])
i[item.Name] = 0;
if(couponCounter[item.Name] == i[item.Name])
{
item.Price = couponTotals[item.Name];
items.Add(item);
}
else
{
item.Price = item.Price - item.Price;
i[item.Name] = i[item.Name] + 1;
}
}
else items.Add(item);
}
}
//ADD IN TAX ITEMS IF SPECIFIED FOR DISPLAY
TaxInvoiceDisplay displayMode = TaxHelper.InvoiceDisplay;
if (displayMode == TaxInvoiceDisplay.LineItem || displayMode == TaxInvoiceDisplay.LineItemRegistered)
{
foreach (OrderItem item in order.Items)
{
//IS THIS A TAX ITEM?
if (item.OrderItemType == OrderItemType.Tax)
{
//IS THE TAX ITEM A PARENT ITEM OR A CHILD OF A DISPLAYED ITEM?
if (!item.IsChildItem || (items.IndexOf(item.ParentItemId) > -1))
{
//TAX SHOULD BE SHOWN
items.Add(item);
}
}
}
}
//SORT ITEMS TO COMPLETE INTITIALIZATION
items.Sort(new OrderItemComparer());
return items;
}