Adding Customer Comments as Order Status Comments using Magento & OneStepCheckout
A few days ago I got an email from someone asking me about adding the default customer comments in OneStepCheckout (www.onestepcheckout.com) as regular order comments. I thought I’d share this quick & simple hack with everyone, so here’s what you have to do:
Open app/code/local/Idev/OneStepCheckout/Helper/Data.php, and after
$observer->getEvent()->getOrder()->setOnestepcheckoutCustomercomment($orderComment);
add this line:
$observer->getEvent()->getOrder()->setState( Mage_Sales_Model_Order::STATE_NEW, true, $orderComment, false );
$observer->getEvent()->getOrder()->setState(
$observer->getEvent()->getOrder()->getStatus(),
true,
$orderComment,
false
);
This will add the comments on the regular comments/statuses thread, as well as a customer comment. If you want to disable customer comments, just comment the original code.
Actually, this approach should also work with the out-of-the-box Magento one step checkout. Add an input on the last step, create a listener for
checkout_type_onepage_save_order
and use the same piece of code:
$observer->getEvent()->getOrder()->setState( $observer->getEvent()->getOrder()->getStatus(), true, $this->_getRequest()->getPost('order_comments'), false );
Note: Tested on Magento 1.4.1.0 & 1.4.1.1


Hi
This approach has it’s flaws especially in 1.3.* series of Magento where order comments can’t be added without changing the actual order status (as we see you set a “new” status here) so be careful when using something like this as your payment method usually sets a status to order and you don’t need the small parts dealing with order process that customer reps has to follow. Triggering order status can fire up additional actions. If you are sure that this is not bothering you this is actually a good way to implement it.
OSC adds a new variable to order in 1.3 series and a new database column for 1.4 with flat order data.
Thanks for the feedback Anton. Indeed, this has only been tested on 1.4.1.x. Initially, I used
$oder->getStatus()and passed that tosetState(), then I thought I’d add a status. But you’re right, this could cause problems, so I’ve slightly changed the article and also added a note for compatibility.You should add a check if status is set or not cause you are making this in order creation time where the status may or may not exist jet.
And of-course you need to test test test cause as I said lot of 3d party modules may listen the status event and send e-mails and stuff. That’s the case this is implemented as a a separate attribute or field in OSC in a first place: to avoid collisions or mishaps that are hard to foresee.
In OSC 3.* the enabling of order comments does not need any template modifications any more so I would leave it as it is.
Well, if the status is not yet set then it shouldn’t trigger anything at all – in theory.
I agree with testing & leaving it as is, especially for OSCv3, but sometimes one may need to add those comments in the order status comments – for example, when using 3rd party software to handle orders.
sure , i’ll write a wiki article based on your blog post.
Thanks 4 this solution, I’ve had allot of problems getting the comment thing to work properly.
Yes, it works great, many thanks. keep posting..
Does anyone know how to mark the original checkout comment as visible on frontend changing the following false to true only sets it to send an email. Are there any other arguments that can be configure for visibility?
true, $orderComment, false