Knowing your repeat customers on the Order Summary page

This forum is where we'll mirror posts that are of value to the community so they may be more easily found.
Post Reply
User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Knowing your repeat customers on the Order Summary page

Post by AbleMods » Tue Sep 23, 2008 7:43 pm

Introduction
This modification will add a new column to your AC7 Order Summary page. The contents of the column will be a clickable number showing the total order history count for the customer that placed the order. This gives you the ability to quickly and easily see which customers are repeat customers without having to switch to the reports page.
The total count is all-inclusive and does not restrict by a particular date range. It is also a link. When clicked, it will take you to the Edit User page so the detailed history for that customer can be viewed.

Modifications
The page file we'll be changing is located in ~/Admin/Orders/. You'll need to change both the default.aspx and default.aspx.cs files, so back them both up before going any further.

Edit the ~/Admin/Orders/default.aspx file first. Look for this section of code:

Code: Select all

                            <asp:TemplateField HeaderText="Customer" SortExpression="BillToLastName">
                                <ItemStyle HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <asp:Label ID="CustomerName" runat="server" Text='<%# string.Format("{1}, {0}", Eval("BillToFirstName"), Eval("BillToLastName")) %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
and replace it with this code:

Code: Select all

                            <asp:TemplateField HeaderText="Customer" SortExpression="BillToLastName">
                                <ItemStyle HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <asp:Label ID="CustomerName" runat="server" Text='<%# string.Format("{1}, {0}", Eval("BillToFirstName"), Eval("BillToLastName")) %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>


                            <asp:TemplateField HeaderText="History" SortExpression="">
                                <ItemStyle HorizontalAlign="Center" />
                                <ItemTemplate>
                                    <asp:HyperLink ID="OrderCount" runat="server" Text='<%# string.Format("{0}",OrderCount(Container.DataItem)) %>' SkinID="Link" NavigateUrl='<%# Eval("UserId", "~/Admin/People/Users/Edituser.aspx?UserId={0}") %>'></asp:HyperLink>
                                </ItemTemplate>
                            </asp:TemplateField>
Done? Good, save it. Now let's edit the ~/Admin/Orders/default.aspx.cs file. Look for this section of code:

Code: Select all

    protected string GetPaymentStatus(object dataItem)
    {
        Order order = (Order)dataItem;
        if (order.PaymentStatus == OrderPaymentStatus.Paid) return "Paid";
        if (order.Payments.Count > 0)
        {
            order.Payments.Sort("PaymentDate");
            Payment lastPayment = order.Payments[order.Payments.Count - 1];
            return StringHelper.SpaceName(lastPayment.PaymentStatus.ToString());
        }
        return order.PaymentStatus.ToString();
    }
and replace it with this code:

Code: Select all

    protected string GetPaymentStatus(object dataItem)
    {
        Order order = (Order)dataItem;
        if (order.PaymentStatus == OrderPaymentStatus.Paid) return "Paid";
        if (order.Payments.Count > 0)
        {
            order.Payments.Sort("PaymentDate");
            Payment lastPayment = order.Payments[order.Payments.Count - 1];
            return StringHelper.SpaceName(lastPayment.PaymentStatus.ToString());
        }
        return order.PaymentStatus.ToString();
    }

    protected string OrderCount(object dataItem)
    {
        Order order = (Order)dataItem;
        return order.User.Orders.Count.ToString();
    }
Save it when you're done. Upload the changes if you have to, then give it a try!

Conclusion
Knowing more about your customers is what makes a good business owner great. Give yourself another edge over your competition by quickly and easily knowing your repeat customers before their order has even been filled.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Knowing your repeat customers on the Order Summary page

Post by compunerdy » Tue Sep 23, 2008 8:38 pm

Very cool mod once again.

Robbie@FireFold
Commodore (COMO)
Commodore (COMO)
Posts: 433
Joined: Wed May 28, 2008 9:42 am
Location: Concord, NC
Contact:

Re: Knowing your repeat customers on the Order Summary page

Post by Robbie@FireFold » Tue Sep 23, 2008 9:38 pm

Sounds like a great mod. I have tried this.. say 6 times with errors everytime.

First I was working just in note pad - easy for me. Couldn't get it to work. Then I used dreamweavers find and replace to make sure I did it exactly how you state.

I still get this error:

Code: Select all

Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

  <%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>
   <system.web>
       <compilation debug="true"/>
   </system.web>
</configuration>

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Admin_Orders_Default.OrderCount(Object dataItem) +48
   ASP.admin_orders_default_aspx.__DataBinding__control63(Object sender, EventArgs e) +76
   System.Web.UI.Control.OnDataBinding(EventArgs e) +99
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +206
   System.Web.UI.Control.DataBind() +12
   System.Web.UI.Control.DataBindChildren() +204
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +216
   System.Web.UI.Control.DataBind() +12
   System.Web.UI.Control.DataBindChildren() +204
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +216
   System.Web.UI.Control.DataBind() +12
   System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +221
   System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +2957
   CommerceBuilder.Web.UI.WebControls.SortedGridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +57
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +59
   System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +11
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +111
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +29
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +50
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
Thoughts?
Robbie Hodge
General Manager
Robbie@FireFold.com
http://www.FireFold.com

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Knowing your repeat customers on the Order Summary page

Post by AbleMods » Tue Sep 23, 2008 10:15 pm

No idea, works fine for me. Even tested it on AbleMods doing a copy/paste from the forum post.

Here are the modified files from my AbleMods AC7 Final SR1 install.
Admin-Orders.zip
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

Re: Knowing your repeat customers on the Order Summary page

Post by William_firefold » Wed Sep 24, 2008 12:48 pm

I tried this and on debug I got this.

Line 303: {
Line 304: Order order = (Order)dataItem;
Line 305: return order.User.Orders.Count.ToString();
Line 306: }
Line 307:
[NullReferenceException: Object reference not set to an instance of an object.]


Whats strange is that the column works and shows (incorrect)data when I use this instead:

Code: Select all

        Order order = (Order)dataItem;
        return order.Payments.Count.ToString();
It seems like the property is not available in this context on our setup, do you know of another way to access it?

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Knowing your repeat customers on the Order Summary page

Post by AbleMods » Wed Sep 24, 2008 12:54 pm

basically it's saying the userid doesn't exit for that order. You using anonymous checkout?
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

Robbie@FireFold
Commodore (COMO)
Commodore (COMO)
Posts: 433
Joined: Wed May 28, 2008 9:42 am
Location: Concord, NC
Contact:

Re: Knowing your repeat customers on the Order Summary page

Post by Robbie@FireFold » Wed Sep 24, 2008 12:58 pm

We have users made accounts.

see http://beta.firefold.com
Robbie Hodge
General Manager
Robbie@FireFold.com
http://www.FireFold.com

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Knowing your repeat customers on the Order Summary page

Post by AbleMods » Wed Sep 24, 2008 1:38 pm

That's completely bizarre.

The only possibility I can think of is that you have an order in your system associated with a user ID that no longer exists.

Have you been placing orders with user accounts and deleting that user account at some point later?
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Knowing your repeat customers on the Order Summary page

Post by compunerdy » Mon Dec 07, 2009 9:23 am

Is it possible to make it so you can sort with this new field?

Post Reply