Page 1 of 1

Coupons in Packing Slip

Posted: Thu Oct 30, 2008 3:14 pm
by William_firefold
How would I go about putting any coupon codes used into the packing slip.

The format i am using is a label:

Code: Select all

<asp:Label ID="CouponCode" runat="server" Text='<%#((OrderShipment)Container.DataItem).Order.Coupons%>'  Font-Size="18px"></asp:Label>
Im stuck there though. Id appreciate any help.

Re: Coupons in Packing Slip

Posted: Fri Oct 31, 2008 12:45 am
by mazhar
You can use the following code to get all the coupons with the order.

Code: Select all

private OrderItemCollection GetCoupons(Object dataItem)
    {
        OrderShipment shipment = (OrderShipment)dataItem;
        Order order = shipment.Order;
        OrderItemCollection coupons = new OrderItemCollection();
        foreach (OrderItem item in order.Items)
        {
            if (item.OrderItemType == OrderItemType.Coupon)
            {
                coupons.Add(item);
            }
        }
        coupons.Sort(new OrderItemComparer());
        return coupons;
    }

Re: Coupons in Packing Slip

Posted: Fri Oct 31, 2008 8:00 am
by William_firefold
This was very helpful, but not quite what I needed. I modified your code to return a string instead. Here it is:

Code: Select all

	private String GetCoupons(Object dataItem)
    {
        OrderShipment shipment = (OrderShipment)dataItem;
        Order order = shipment.Order;
        String coupons = "";
        foreach (OrderItem item in order.Items)
        {
            if (item.OrderItemType == OrderItemType.Coupon)
            {
                coupons+= (item).Name +"<br />";
            }
        }        
        return coupons;
    }
This is how I Called it:

Code: Select all

                <asp:Label ID="CouponLabel" runat="server" Text="Coupon:" SkinID="fieldheader" Visible='<%# (GetCoupons(Container.DataItem)!="") %>'></asp:Label>
                <asp:Label ID="CouponCode" runat="server" Text='<%# GetCoupons(Container.DataItem)%>'  Font-Size="18px"></asp:Label>      

Re: Coupons in Packing Slip

Posted: Fri Oct 31, 2008 8:04 am
by mazhar
That's great. I just tried to provide you an idea that how to get coupon information.

Re: Coupons in Packing Slip

Posted: Fri Oct 31, 2008 8:26 am
by bobr2k
I think it's great that you each "chipped in" -- a great help to those of us who are less talented in this field.
Thanks!