Home > Magento > Adding Customer Comments as Order Status Comments using Magento & OneStepCheckout

Adding Customer Comments as Order Status Comments using Magento & OneStepCheckout

October 24th, 2010

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

  1. Cristi
    | #1

    I haven’t tried any extension that does that, but the Amasty plugin seems to allow what you need, and from experience, Amasty extensions are usually well coded and take care of the intended job pretty well. i’d say give it a try and if it’s not helping just ask for a refund. another option would be to code the feature as a custom module. good luck!

  2. Linda
    | #2

    Hello,
    I need to add 2 dependable dropdowns. How can I do that? For now I’ve found only that extension to complete the task http://amasty.com/order-attributes.html. Have you tried it or some other ones?

  3. Cristi
    | #3

    hi, i went to your store and reached the checkout page and you don’t seem to have OneStepCheckout installed. This post is about OSC, mostly. Your approach should work, but it depends on what you do, what you want to accomplish and where you hook it. from what you’re describing it looks like a javascript error. hope that helps.

  4. vikas
    | #4

    Hi,

    Hi,

    first of all , Thanks a lot for your support.

    please visit http://steel.newtrendzonline.com/

    please “Add to cart” some products, after go for checkout . In checkout page, in 3rd step 3) Shipping Method,

    we added the comment box, but below “SUBMIT button” is not working.

    The same code for “submit button” , which we used in “Contact form page” is working.

    [mails are sending to contacts “e-mail”] . But the “submit” button code” is not working

    under 3)Shipping method in Checkout. [mails are not sending to contacts “e-mail”].

    I edited the shipping_method.phtml file in proper way. Is there anything else i have to do?

    I sent the shipping_method.phtml file to support@magentech.com.

    I am aiting for your solution.

    please give me the solution.

    Thanks in Advance.

  5. Scott
    | #5

    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

  6. Pratik
    | #6

    Yes, it works great, many thanks. keep posting..

  7. | #7

    Thanks 4 this solution, I’ve had allot of problems getting the comment thing to work properly.

  8. Anton
    | #8

    sure , i’ll write a wiki article based on your blog post.

  9. Cristi
    | #9

    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.

  10. Anton
    | #10

    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.

  11. Cristi
    | #11

    Thanks for the feedback Anton. Indeed, this has only been tested on 1.4.1.x. Initially, I used $oder->getStatus() and passed that to setState(), 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.

  12. | #12

    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.

  1. No trackbacks yet.