Magento Order Comments

Recently we had a request from a client to add a comment to orders (ie. the checkout process). If you have ever wanted to add a field where customers can enter comments to their order, follow on below to see how this can be added as an extension

First lets add the textarea field to the checkout review page.
We will copy the default file into our namespace and make changes there.
In your magento directory go to app/design/frontend/ and create the namespace directory and the others after it. I will use mcorner for our example mcorner/default/template/checkout/onepage/review. Make sure that you create the folder structure within the template namespace that your magento website is using at the moment.
Then copy the file info.phtml from the app/design/frontend/base/default/template/checkout/onepage/review directory into the newly created path.
Now we are ready to edit the info.phtml file in our namespace path. Here we have added the textarea to the form, lines 72-78.

 <div id="checkout-review-submit">
     <?php echo $this->getChildHtml('agreements') ?>
     <form action="" id="checkout-agreements" onsubmit="return false;">
       <div class="checkout-comments">
         <label for="orderComment"><?php echo $this->__('Order Comments (optional)'); ?></label>
         <textarea name="orderComment" id="orderComment" rows="3" cols="60"></textarea>
     <div class="buttons-set" id="review-buttons-container">

In your magento directory go to /app/code/local/ and create your namespace. I am using MCorner.
So create MCorner/OrderComments/etc and add the file config.xml with the following code:

 <?xml version="1.0"?>

Now we will setup the Observer.
In app/code/local/MCorner/OrderComments create the Model directory and within it the file Observer.php with the following code:

 class MCorner_Ordercomments_Model_Observer extends Varien_Object
     * Add a customer order comment when the order is placed
     * @param object $event
     * @return
     public function saveOrder($evt)
       $_order   = $evt->getOrder();
       $_request = Mage::app()->getRequest();

       $_comments = strip_tags($_request->getParam('orderComment'));

         $_comments = 'Additional Order Comments: ' . $_comments;

       return $this;

This will add a comment that will be displayed in the comments setion of the order in the Admin.

Last file we need to add is in app/etc/modules
Create file MCorner_All.xml with the following:

 <?xml version="1.0"?>

That’s it. Clear Magento’s cache and go test your new extension.
This extension works on version 1.6.0 –