2

Is there any tutorial available for how do i add custom fields on front end check out step like PO number,Job name , customer comments etc as well as in admin->create->order.

magento2new
  • 517
  • 1
  • 10
  • 38

1 Answers1

3

My usual motto is to find (and buy if needed) a module that already has the functionality you seek. Especially when the life of this project involves version upgrades because then you can seek a pre-packaged solution from the provider.

I regret every bit of custom code I have added to our Magento install. Because now I've got to maintain the site to just keep working in addition to figuring out my hacks. Time to devote more time to replacing hacks with off-the-shelf extensions, which would have been much faster in the first place.

I know this attitude goes somewhat against the stack overflow thinking of I can do anything, but really, Magento's job is to enable someone to do less work.


Two years later, an update: after the gentle poke of a downvote (probably for appearing to shrug off the question), I am back to revisit and share some of what I've learned. The programming aspect of additional fields is the concept of persistence of the data.

If you're ok with the custom fields only appearing in the transactional emails following the order, then the task is as "simple" as adding the fields to the form somewhere and then updating the controller to to catch and insert the post data into the email. You can use a custom variable in the back end to readily expose this to the email templates. And a Magento SE on programatically creating a custom variable.

Getting persistence into the back end requires adding database fields via an installer in your module. The iCoreThink blog lays out the steps clearly and explains why, how to confirm your work, and then provides real-world implementation, like displaying to the customer in their account. The "other blog" mentioned below has a great example of this, though his example is specifically related to billing and shipping.


Resources from my upvotes and bookmarks:
» This iCoreThink blog post is my favorite reference so far and what I'm following now.

» I was using Templates Master's FireCheckout which includes their own checkoutfields module, but I've abandoned their single view checkout for the flow of Magento's one page checkout. I'm now trying to adapt their checkout fields (and use their controller) into my template for checkout.

» I thought for sure Alan Storm wrote an article about Checkout custom fields, but I don't see one.

» This Magento SE lists a couple blogs and a paid extension. The excellence blog is ok, but his style is too rote for me and I don't learn anything. The other blog discusses the procedure for building your module and installing the database fields.

» The unexpected-IT blog demonstrates and informal hack to add the code to core files (but sadly doesn't show how to override those files by copying them to app/code/local) and the steps to manually perform to get the column and fields added in the database. Apparently is perfect for 1.4 and below, but comments seem to explain what to do for 1.5 and up.

This last hack-ish change is my personal favorite as it seamlessly adds the extra bits into existing Magento admin pages and "feels like" less work. Caveats: I wouldn't do this without using version control and it will absolutely break if any core code changes happen between version upgrades.

Community
  • 1
  • 1
Krista K
  • 21,503
  • 3
  • 31
  • 43
  • Thanks for resources, very useful. Just a word of warning: iCoreThink tutorial starts well but then they fail to include code of 2 Model classes Icorethink_Custom_Model_Custom_Order, Icorethink_Custom_Model_Custom_Quote. I am not sure if the module will work without them. Do you have this code by any chance? – Alan Sep 29 '14 at 14:47
  • It seems to be a Ctrl+C/V copy of [ExcellenceMagento tutorial](http://excellencemagentoblog.com/magento-add-custom-fields-checkout-page). To get these classes download source code from their website :). – Alan Sep 29 '14 at 14:58
  • Thanks for noticing that, Alan! – Krista K Sep 29 '14 at 19:22
  • +1 for "Find and buy" as it is really much better than hacking a solution if there is a good module that does what you need (supported) – Kender Apr 27 '15 at 18:10