Improve the Order Status Display Grid

by Joe Payne 20. April 2008 00:19
Introduction
It's always important as a site admin to know what the customer will be seeing when they visit your site. In this short tutorial, we're going to make it easier for the site admin to work with Order Statuses.

Once you have several order status codes created, it becomes increasingly important to keep track of what each status will display on the customer side of the store. But to do that now, you have to edit each status one-by-one to see what the "Display Name" value is. This quick-and-easy modification adds the Customer-side "Display Name" field to the Configure, Order Status grid. Once completed, the site admin can quickly and easily see what the customer will see for each order status.

This modification assumes AC7 RC3

Easy Fix
This change is very simple. Just edit the ~/Admin/Store/OrderStatuses/Default.aspx file and look for this line of code:
Code:
<asp:BoundField HeaderText="Name" DataField="Name" SortExpression="Name" HeaderStyle-HorizontalAlign="Left" />


and change it to look like this:
Code:
<asp:BoundField HeaderText="Name" DataField="Name" SortExpression="Name" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField HeaderText="Display Name" DataField="DisplayName" SortExpression="DisplayName" HeaderStyle-HorizontalAlign="Center" />


Done!

How it Works
The Order Statuses page is a very simple page. It uses a .Net datasource control to provide records to a .Net GridView control. All we've done is add another field column that tells the GridView control to also show the "Display Name" field provided by the data source control.

We also made a minor change from "Left" to "Center" on the horizontal alignment of the column headings. This is purely optional.

Conclusion
Any easy change that helps the site admin know what the customer is going to see with each order status.

Tags: ,

AC7 Articles

Add custom settings available store wide

by Joe Payne 15. April 2008 00:22
Introduction
As you get deeper into programming in AC7, you might find the need have a parameter specified on the Admin side that needs to be acted upon on the store side. All of the AC7 store-wide settings are stored in the ac_StoreSettings table. What's interesting is the CommerceBuilder API gives you some *very* easy methods to store and retrieve your own custom settings.

An Example Goal
The best way to learn is by-example, so let's make up a need and accomplish that need using this technique. For today's example, we have a request to create a catch-all AC7 page for visitors who request a missing product. Apparently the site admin recently decided to rebuild part of the product catalog. Well, that "broke" all those product URLs since the Product ID is tied to the URL and alot of visitor landings are getting the generic IIS "page missing" errors. The sales manager says "fix it, make it clean and don't you dare hard-code it!". Pffft like the sales manager even KNOWS what hard-coding means, but that's a debate for another time.

Project Definition
1. Failed product lookups must redirect to an AC7-controlled page. The server administrator doesn't want you playing with IIS site settings.

2. The designated redirect page must be configurable on the Admin side. The only other thing managers do well besides creating unrealistic expectations is changing their minds AFTER you coded everything.

3. Programming testing if the value has been specified on the Admin side should be easy to do. You're the one stuck with this project and that Friday night trip to the riverboat casino didn't help getting you up for work this morning.

The Admin Side Changes
Every good project has an even better foundation. We're going to integrate this change right into the main AC7 Store, Configure menu option. The site admin will be pleased. Let's start by editing the ~/Admin/Store/StoreSettings.aspx and adding a text box control with label to the page. Look for this code in the page near the bottom:

Code:
                        <asp:Label ID="ProductPurchasingDisabledLabel" runat="server" Text="Enabling this feature will hide the add to basket button for all products, so customers can browse your catalog but are unable to purchase directly online."></asp:Label><br />
                        <asp:CheckBox ID="ProductPurchasingDisabled" runat="server" Text="Enable Catalog Mode"/>


and replace it with this code:

Code:
                        <asp:Label ID="ProductPurchasingDisabledLabel" runat="server" Text="Enabling this feature will hide the add to basket button for all products, so customers can browse your catalog but are unable to purchase directly online."></asp:Label><br />
                        <asp:CheckBox ID="ProductPurchasingDisabled" runat="server" Text="Enable Catalog Mode"/>
                        <br />
                        <asp:Label ID="lbl_ProductMovedPage" runat="server" Text="Redirect page for invalid Products (blank redirects to home page):"></asp:Label><br />
                        &nbsp;<asp:TextBox ID="txt_ProductMovedPage" runat="server" Width="310px"></asp:TextBox><br />


Once you've added the text box, we have to modify both the Load section and the Save section of the page. The site admin will be able to always see what the current setting is and make changes to it all on the same page. Look towards the top of the page in the Page_Load function for this code:

Code:
         //GIFT CERTIFICATE EXPIRY
            GiftCertExpireDays.Text = settings.GiftCertificateDaysToExpire.ToString();


and replace it with:
Code:
         //GIFT CERTIFICATE EXPIRY
            GiftCertExpireDays.Text = settings.GiftCertificateDaysToExpire.ToString();

            //BEGIN: Solunar.com Mod
            // Moved Product Page URL
            txt_ProductMovedPage.Text = settings.GetValueByKey("CUSTOM:BadProductPage");
            //END: Solunar Mod


All done? Perfect. But we still have to make the system save any changes made. So let's move down into the SaveSettings() function and find this section of code:

Code:
        //Gift Certificate Days to Expire
        settings.GiftCertificateDaysToExpire = AlwaysConvert.ToInt(GiftCertExpireDays.Text);
       
        //BEGIN: Solunar Mod
        //Missing Page URL
        settings.SetValueByKey("CUSTOM:BadProductPage", txt_ProductMovedPage.Text);
        //END: Solunar Mod


Save your changes and test the page. You should have a new text box field located on the bottom-right of the Configure, Store page. Enter something (anything) in the field and save the settings. Now switch to another page and then back again to the Configure, Store page to ensure the changes you made were saved. If you did everything right, you'll see the test value you entered already populated in the text box.

The Store Side
So all this work just to store one value on the Admin side was fun, but how does it help you? Well, we now have a custom user-specified value that is easily editable on the Admin side. All we have to do now is know how to retrieve that value on the store side. For our example today, we're going to edit the BuyProductDialog.ascx user control. Every product page uses it, so it's a good place to put in a test for an invalid product and redirect to our new custom URL.

Let's start by editing the BuyProductDialog.ascx.cs code file located in the ~/ConLib/ folder. Look for this code at the end of the Page_Init function, directly above the start of the next subroutine UpdateInventoryDetails():

Code:
        else
        {
                Response.Redirect(NavigationHelper.GetHomeUrl());
        }


and replace it with:

Code:
        else
        {
            //BEGIN: Solunar Mod
            // ProductId not found, redirect to the badproductpage
            // Retrieve redirect URL for missing products
            StoreSettingCollection settings = Token.Instance.Store.Settings;
            string _BadProductPage = settings.GetValueByKey("CUSTOM:BadProductPage");
            if (string.IsNullOrEmpty(_BadProductPage))
            {
                Response.Redirect(NavigationHelper.GetHomeUrl());
            }
            else
            {
                Response.Redirect(_BadProductPage);
            }
            //this.Controls.Clear();
            //END: Solunar Mod
        }


Save it.

What's Happening?
Study the above code for a minute. Retrieving a value in the StoreSettings table is incredibly easy. It's always available because the Store data class is always available. So first things first, we grab the store settings collection from the Store data class and assign it to a seperate variable. While this is an extra step, it makes for easy-to-read code and that's always a good programming practice.
By calling the GetValuebyKey() function, we've told the data class to search the ac_StoreSettings table for a key named "CUSTOM:BadProductPage" and return the value assigned to that key. If no value is returned i.e. the key couldn't be found, the code will simply redirect the user to the home page. But if a value is returned, then use that value as the destination redirect page. Cool!

Testing
Let's test all of this now. Build a web page you want to be displayed for missing products. Call it MovedProduct.aspx and store in the root of your store. Now go back into the Admin side of the store and enter ~/MovedProduct.aspx as the value for the your new custom field in the Configure, Store page.
Finally, the test. Fire up your browser and enter your store URL with a bad ProductId value like
http://www.mystore.com/Product.aspx?ProductId=99999 and see what happens. The original AC7 design would have dumped you back to the home page - not terribly intuitive from a visitor perspective. But you should be redirected to your brand new MovedProduct page instead. Now you can offer the visitor additional search options, explain why they got there or even offer to sell a substitute product.

Conclusion
Creating admin-side custom settings that can be retrieved on the store side is very powerful. It gives the developer the ability to offer admin-manageable features without hard-coding or repeated programming changes. AC7 gives you all the tools you need to create and access customized settings from anywhere within the store front.

Tags: ,

Month List