Access Comments from Credit Memo After sales_order_creditmemo_refund Event

creditmemomagento-1.7orders

I am generating XML which is sent to an external system whenever a Credit Memo is generated. I am using the event sales_order_creditmemo_refund which gives me the credit memo and order models (which I am using to generate the appropriate XML)

$creditMemo = $observer->getEvent()->getCreditmemo();
$order      = $creditMemo->getOrder();

However I am having trouble accessing comments. I can see in Mage_Sales_Model_Order_Creditmemo there is getCommentsCollection() but this is not returning anything.

I am guessing the comments are added to the model at a later stage, should I be using a different event for my observer?

I can see that Mage::dispatchEvent('sales_order_creditmemo_refund', array($this->_eventObject=>$this)); is located inside the refund() method of the same model, but the only other event I can see in the model is sales_order_creditmemo_cancel

Best Answer

Ok so after posting the question I immediately find the answer!

For anyone else with this issue:

Checking the saveAction() within Mage_Adminhtml_Sales_Order_CreditmemoController reveals that the comments are initially only added to the session:

$data = $this->getRequest()->getPost('creditmemo');
if (!empty($data['comment_text'])) {
   Mage::getSingleton('adminhtml/session')->setCommentText($data['comment_text']);
}

So from within the observer I can simply call Mage::getSingleton('adminhtml/session')->getCommentText() to return the comment.

Related Topic