Adding custom fields
Adding custom fields
We would like to add a couple of custom fields on the checkout page of the order process--an Industry Code dropdown list and an Order Source dropdown list. It would be nice if we can store the Industry Code data with the customer information (i.e. address) and the Order Source data is only valid with one specific order. Where do you recommend placing these fields as far as the table data goes? I understand there is a user settings table available--do you think this is most appropriate for the Industry Code? What about Order Source? We would like to be able to refer back to this data in the admin interface if possible. Other than writing custom code, is there anything else we need to do with the user settings table to store the industry code data? I'm very new at customizing AbleCommerce and usually code in VB...any help would be great. Thanks in advance.
Re: Adding custom fields
If you want to store industry code data with each user without making database change then it would be better to make use of Comment field available with customer information instead of using user settings. Please read following postIt would be nice if we can store the Industry Code data with the customer information (i.e. address)
viewtopic.php?f=47&t=6813
Secondly regarding Order Source information one solution could be to make use of ac_CustomFields. Please read following thread about their usethe Order Source data is only valid with one specific order
viewtopic.php?f=42&t=8651
The other possible solution could be to create some custom table to store this information. If you want to proceed with this then read following thread about auto generating data access code for your custom table
viewtopic.php?f=47&t=9530
Re: Adding custom fields
I started out trying to implement the Industry Code user defined field--the only difference from the example you provided is I need this user defined field on the checkout page so that the customer can identify their industry code. The part I can't seem to get working is getting the comment field to update with a new value. I first added a dropdown list box on the checkout page. Then I added this code to the page load event:
User _User = Token.Instance.User;
IndustryCodeDropDownList.SelectedValue = _User.Comment;
Then I added this code to the continue button click event to save the value to the comment field:
User _User = Token.Instance.User;
_User.Comment = IndustryCodeDropDownList.SelectedValue;
_User.Save();
In testing the changes, I added an item to my basket, proceeded to check out, logged in as a user, indicated "Agent/Broker" as the Industry Code and completed the checkout. When I look in the User table, I do see that "Agent/Broker" is the new value in the comment field. However, when I step through this checkout process a second time using the same user, I choose "Insurance Company" as the Industry Code, but the comment field still shows "Agent/Broker" as the value (it should say "Insurance Company"). Is there something I'm missing?
User _User = Token.Instance.User;
IndustryCodeDropDownList.SelectedValue = _User.Comment;
Then I added this code to the continue button click event to save the value to the comment field:
User _User = Token.Instance.User;
_User.Comment = IndustryCodeDropDownList.SelectedValue;
_User.Save();
In testing the changes, I added an item to my basket, proceeded to check out, logged in as a user, indicated "Agent/Broker" as the Industry Code and completed the checkout. When I look in the User table, I do see that "Agent/Broker" is the new value in the comment field. However, when I step through this checkout process a second time using the same user, I choose "Insurance Company" as the Industry Code, but the comment field still shows "Agent/Broker" as the value (it should say "Insurance Company"). Is there something I'm missing?
Re: Adding custom fields
I suspect that its saving the information the only differance is that its saving very same informaton again. Make sure loading code within Page_Load method runs only once. Try putting your industry code loading code within
Code: Select all
if(!Page.IsPostBack)
{
//YOU Industry Loading code here
}
Re: Adding custom fields
Thanks! That fixed the problem! I'm starting to work on the Order Source piece and will get back with you if I run into any problems.
Re: Adding custom fields
At what point in the checkout process is the order id actually assigned? I am new to C# and in trying to implement the code you suggested, but am receiving an "object set to null reference" error because there is no order id available from the checkout page...it's not available until after you complete checkout so how do I get the order source code (set on the first page of checkout) to store on the order?mazhar wrote:Secondly regarding Order Source information one solution could be to make use of ac_CustomFields. Please read following thread about their usethe Order Source data is only valid with one specific order
viewtopic.php?f=42&t=8651
Re: Adding custom fields
Imidiatily after placement of order the very first location where you can access orderid is Checkedout method of OnePageCheckout control. You can access order there as below
Code: Select all
Order order = OrderDataSource.Load(e.OrderId);
.............
.............
Re: Adding custom fields
Now I'm trying to take the industry code that was stored in the custom fields table and make it viewable on the ViewOrder.aspx page in the admin site. Do you have any example code I can refer to for this?