Best way to add custom field to order?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
wilhud
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Mon Mar 30, 2009 7:44 pm

Best way to add custom field to order?

Post by wilhud » Fri Oct 02, 2009 12:46 pm

I'm using AC 7.0.2 and want to add a custom field to the checkout. What is the best way to go about this? The field I will require is a 6-digit catalog code that we use when mailing customers their physical catalogs that they look at and then order online.

I've read some other posts suggesting to use the coupon code field, but we are using that field for actual coupons. I've also read some suggestions about using the notes field, but we will be utilizing that field for notes, plus I will want to run reports on these catalog codes in the future, so I will need to be able to query the db for all orders using catalogcode = 081001 and such. So trying to do that with a notes field would just be sort of messy.

I've also read that there may be some of this functionality in 7.0.3. Can anyone confirm this? Can you easily add the custom fields to the order checkout process? If so, I would probably want to upgrade, but I have a lot of custom coding on the categories and nav sections of the site, so I'd like to try and keep from having to re-do a bunch of stuff...if possible. Any ideas or suggestions are greatly appreciated.

Thanks,
Wil

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

Re: Best way to add custom field to order?

Post by mazhar » Mon Oct 05, 2009 5:37 am

You should better create some custom table and then associate it with your orders table through order id and then put your custom information on this table.

wilhud
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Mon Mar 30, 2009 7:44 pm

Re: Best way to add custom field to order?

Post by wilhud » Thu Oct 29, 2009 9:34 pm

So I setup a custom table in the db linked to the order id. I setup a script to add the Catalog code value to the new table, but am unsure of where this needs to be placed. I tried putting it in the OnePageCheckout file in the ConLib and in the PlaceOrder2 file in the Order Admin but the OnePageCheckout file does not take into account orders that are placed through the PaymentPage and the PlaceOrder2 file only works for orders that are deferred. I don't want to have to apply the same script to each payment option, so is there one central place I can add my insert to so that it will occur during all checkouts? The catalog code field is already in each of the areas it needs to be, but I just need to figure out where the insert should be placed. Would it go in the App_Code CheckoutEvent? And if so, how would I pull the OrderId and field value from there?

Any suggestions are greatly appreciated.

Thanks,
Wil

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

Re: Best way to add custom field to order?

Post by mazhar » Fri Oct 30, 2009 4:40 am

In OnePageCheckout.ascx.cs file you will found a method CheckedOut. This event handler is called by AbleCommerce after placing every order completed via customer checkout. So you need to place your code in this event handler. In order to access newly placed order you need to get order id out of the event argument passed to this event handler something like

Code: Select all

int orderId = e.OrderId; //Get newly placed order id on OnePageCheckout
Order order = OrderDataSource.Load(orderId,false) //load order by using order id

wilhud
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Mon Mar 30, 2009 7:44 pm

Re: Best way to add custom field to order?

Post by wilhud » Fri Oct 30, 2009 12:41 pm

Hi Mahzar,

Thanks for the reply.

That's where I put the script for the OnePageCheckout.ascx.cs and it works fine. However, if the customer splits shipments and ends up on the Payment.aspx page for checkout, I'm having trouble adding the same type of script. It seems there are multiple user controls taking payment on this page and none of them call upon a common method like on the OnePageCheckout it appears. Hmmm, I wonder if I can add a method onto the Payment page using the same basic concept as the OnePageCheckout's CheckedOut method. I'll have to see.

Also, I'm having the same issue with the admin side, as well. Multiple payment methods that are not all triggering the same checked out method. I'll have to dig into that one some more and see if the same concept may apply.

Wil

wilhud
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Mon Mar 30, 2009 7:44 pm

Re: Best way to add custom field to order?

Post by wilhud » Fri Oct 30, 2009 10:01 pm

That actually did work. I used the exact same method from the OnePageCheckout page and applied it to the ConLib PaymentPage. I'll need to see what I can do on the admin form now to try and get the same thing working.

Wil

wilhud
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Mon Mar 30, 2009 7:44 pm

Re: Best way to add custom field to order?

Post by wilhud » Tue Nov 03, 2009 4:10 pm

I am finding the admin checkout page much more difficult to manipulate than the front end of the store in this case. I was able to find the code in the CreditCardButton_Click portion of the CreditCardPaymentForm.ascx file, where adding my code to store the custom field info may be able to be placed. However, when I put it there, I cannot retrieve the value from the parent form. I can pull the OrderNumber and OrderId fine with checkoutResponse.OrderNumber and checkoutResponse.OrderId but trying to get my custom field values isn't working because I'm inside of a user control. Anyone know a simple way to get around this? I've seen numerous sites talking about using invokemember for calling a parent method and I've also seen other sites talking about ways to try and get the parent form values into the user control, but they're all very confusing.

Any help or suggestions are greatly appreciated. This one is much tougher than I expected.

Thanks,
Wil

wilhud
Lieutenant (LT)
Lieutenant (LT)
Posts: 66
Joined: Mon Mar 30, 2009 7:44 pm

Re: Best way to add custom field to order?

Post by wilhud » Tue Nov 03, 2009 11:57 pm

Well, I needed a fix for this asap, so instead of fussing with it any longer, I just added duplicate custom fields to the credit card user control and placed my db insert directly into the user control for credit card payments. It's kind of redundant when you look at the form on screen, but at least it will get the data into the system for now. Pretty ugly, but I needed it in there because we're taking orders already.

So now in the admin it's....

Payment Method:
Catalog Code Field
Order Type Field

Defer Payment Button
-----
Catalog Code Field 2
Order Type Field 2

Credit Card Type Dropdown
Name On Card Field
Card Number Field
Exp Date Fields
Verification Code Field
Pay With Card Button

It gets the job done for now and only CSRs see it. Was able to get the front end to work with one set of fields.

Wil

Post Reply