Magento – How to get Post Data from Magento’s Onepage Checkout

checkoutmagento

in order to add a customers comment field in the Magento Checkout, I added a text field in the appropriate template file and added the comment to the order using an observer like this:

        $comment = strip_tags(Mage::app()->getRequest()->getParam('cpOrderComment'));  

        if(!empty($comment)){  
           $observer->getEvent()->getOrder()->setCustomerNote($_comments);              
        } 

This worked perfectly using the OnestepCheckout extension, however it does not work with Magento's Onepage Checkout. The "getParam('cpOrderComment')" is always empty and now I not sure how to get the value of my text field.

Any ideas would be greatly appreciated!

Best Answer

This problem is solved. The review part of the checkout is submited by the save function in skin/frontend/base/default/js/opcheckout.js around line 820.

This function does not take all fields into account from the agreements.phtml, but only the ones inside $('ol#checkout-agreements') - go figure...

The solution is obviously to to put the field inside the ul#checkout-agreements or to change opcheckout.js to include all the fields from the agreements.phtml.

Related Topic