Adding a salutation to Billing and Shipping addresses

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
jdarby
Commander (CMDR)
Commander (CMDR)
Posts: 151
Joined: Thu Sep 25, 2008 2:21 pm

Adding a salutation to Billing and Shipping addresses

Post by jdarby » Fri May 29, 2009 9:47 am

Is there a way to add a required field for Salutation (Mr., Mrs. etc.) on the checkout pages? Just realized that there is not a field for this and we will have correspondence going out and need to know how to address our customers.

Thanks.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Adding a salutation to Billing and Shipping addresses

Post by mazhar » Fri May 29, 2009 10:01 am

Yes its possible, address table contains an unused field Nickname, you can make use of that field to contain this info. For example here is the code required for billing address you can do very same thing for shipping address as well.

Edit ConLib/OnePageCheckout.ascx file and locate following code

Code: Select all

                                            <tr>                        
                                                <th class="rowHeader">
                                                    <asp:Label ID="BillToFirstNameLabel" runat="server" Text="First Name:" AssociatedControlID="BillToFirstName" EnableViewState="false"></asp:Label>
                                                </th>
                                                <td>
                                                    <asp:TextBox ID="BillToFirstName" runat="server" EnableViewState="false" Width="120px" MaxLength="20" ValidationGroup="OPC"></asp:TextBox> 
                                                    <asp:RequiredFieldValidator ID="BillToFirstNameRequired" runat="server" Text="*"
                                                        ErrorMessage="First name is required." Display="Static" ControlToValidate="BillToFirstName"
                                                        EnableViewState="False" SetFocusOnError="false" ValidationGroup="OPC"></asp:RequiredFieldValidator>
                                                </td>
                                            </tr>
and then change it as below

Code: Select all

<tr>                        
                                                <th class="rowHeader">
                                                    <asp:Label ID="Label1" runat="server" Text="Salutation:" AssociatedControlID="BillToSalutation" EnableViewState="false"></asp:Label>
                                                </th>
                                                <td>
                                                    <asp:TextBox ID="BillToSalutation" runat="server" EnableViewState="false" Width="120px" MaxLength="20" ValidationGroup="OPC"></asp:TextBox> 
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorSalutation" runat="server" Text="*"
                                                        ErrorMessage="Salutation is required." Display="Static" ControlToValidate="BillToSalutation"
                                                        EnableViewState="False" SetFocusOnError="false" ValidationGroup="OPC"></asp:RequiredFieldValidator>
                                                </td>
                                            </tr>
                                            <tr>                        
                                                <th class="rowHeader">
                                                    <asp:Label ID="BillToFirstNameLabel" runat="server" Text="First Name:" AssociatedControlID="BillToFirstName" EnableViewState="false"></asp:Label>
                                                </th>
                                                <td>
                                                    <asp:TextBox ID="BillToFirstName" runat="server" EnableViewState="false" Width="120px" MaxLength="20" ValidationGroup="OPC"></asp:TextBox> 
                                                    <asp:RequiredFieldValidator ID="BillToFirstNameRequired" runat="server" Text="*"
                                                        ErrorMessage="First name is required." Display="Static" ControlToValidate="BillToFirstName"
                                                        EnableViewState="False" SetFocusOnError="false" ValidationGroup="OPC"></asp:RequiredFieldValidator>
                                                </td>
                                            </tr>
Now edit ConLib/OnePageCheckout.ascx.cs file and locate following code

Code: Select all

BillToFirstName.Text = billingAddress.FirstName;
and change it as below

Code: Select all

BillToSalutation.Text = billingAddress.Nickname;
BillToFirstName.Text = billingAddress.FirstName;
Locate following code

Code: Select all

billingAddress.FirstName = StringHelper.StripHtml(BillToFirstName.Text);
and change it as below

Code: Select all

billingAddress.Nickname = StringHelper.StripHtml(BillToSalutation.Text);
billingAddress.FirstName = StringHelper.StripHtml(BillToFirstName.Text);

CASE
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 49
Joined: Tue Jan 22, 2008 7:18 am

Re: Adding a salutation to Billing and Shipping addresses

Post by CASE » Thu Jun 25, 2009 3:23 pm

Thank you so much. It works perfectly. If I do want to add an additional third field, is it very complicated? I've already tried adding it to the the database (Address3) and modifying the code but get the following error.

[[ConLib:OnePageCheckout]] d:\commerce\ConLib\OnePageCheckout.ascx.cs(696): error CS0117: 'CommerceBuilder.Users.Address' does not contain a definition for 'Address3'

I am not sure how to edit 'CommerceBuilder.Users.Address' or even if it is possible.

mwolf
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 50
Joined: Mon Jul 02, 2007 9:37 pm
Location: Chicago, IL
Contact:

Re: Adding a salutation to Billing and Shipping addresses

Post by mwolf » Thu Jun 25, 2009 8:07 pm

Hi CASE,

Adding Address3 will not work like that. As far as I know, you will need to create a custom query that saves the Address3 value to the database in to a custom database field. The reason Nickname worked by simply adding those two lines of code is because that is a standard Ablecommerce field.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Adding a salutation to Billing and Shipping addresses

Post by mazhar » Fri Jun 26, 2009 8:45 am

Instead of adding a brand new field for Address 3 what about trying following work around. The concept is to make use of Nickname field to accommodate two values separated by some special character for example | pipe sign. You can have two different UI elements for input but in back end when trying to save data concatenate values from both text boxes something like

Code: Select all

address.Nickname = text1.Text+"|"+text2.Text;
Similarly when it comes to show the saved information you can first split Nickname value over | sign and then update respective UI elements to show that information. For example

Code: Select all

string[] values = address.Nickname.Split('|');
text1.Text = values[0];
text2.Text = values[1];
If nick name field size seem small, you can increase it to accommodate both values.

CASE
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 49
Joined: Tue Jan 22, 2008 7:18 am

Re: Adding a salutation to Billing and Shipping addresses

Post by CASE » Mon Jun 29, 2009 8:06 am

Thank you. We've decided to go without the third field.

On the payment options page in the checkout, where the shipping and billing addresses are listed out, it doesn't show the two added fields. If I select edit on this page, the extra fields do display on the edit address page. Is there something else that I need to edit to make these fields show?

In the attached image, both billing and shipping should show a title and address 3 field.

Post Reply