title: Magento - Adding order comments from observer events
body: <p>I've been really beating myself up over this up, hopefully someone can help me out. </p>
  
  <p>I have a few observer events working perfectly, it's just one that doesn't seem to work.</p>
  
  <p>The creditmemoRefund function won't add a comment to the order. The order 2 work fine, it's definitely firing like intended, and does pull the order object. Why won't it add a comment?</p>
  
  <p>Here's my code...</p>
  
  <p>config.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;config&gt;
    &lt;modules&gt;
      &lt;Avi_OrderAudit&gt;
        &lt;version&gt;0.0.1&lt;/version&gt;
      &lt;/Avi_OrderAudit&gt;
    &lt;/modules&gt;
    &lt;global&gt;
  &lt;helpers&gt;
    &lt;orderaudit&gt;
      &lt;class&gt;Avi_OrderAudit_Helper&lt;/class&gt;
    &lt;/orderaudit&gt;
  &lt;/helpers&gt;
  &lt;models&gt;
    &lt;orderaudit&gt;
      &lt;class&gt;Avi_OrderAudit_Model&lt;/class&gt;
      &lt;resourceModel&gt;orderaudit_mysql4&lt;/resourceModel&gt;
    &lt;/orderaudit&gt;
  &lt;/models&gt;
  &lt;events&gt;
    &lt;sales_order_place_after&gt; &lt;!-- identifier of the event we want to catch --&gt;
      &lt;observers&gt;
        &lt;sales_order_place_after_handler&gt; &lt;!-- identifier of the event handler --&gt;
          &lt;type&gt;model&lt;/type&gt; &lt;!-- class method call type; valid are model, object and singleton --&gt;
          &lt;class&gt;orderaudit/observer&lt;/class&gt; &lt;!-- observers class alias --&gt;
          &lt;method&gt;orderPlaced&lt;/method&gt;  &lt;!-- observer's method to be called --&gt;
          &lt;args&gt;&lt;/args&gt; &lt;!-- additional arguments passed to observer --&gt;
        &lt;/sales_order_place_after_handler&gt;
      &lt;/observers&gt;
    &lt;/sales_order_place_after&gt;
    &lt;sales_order_payment_capture&gt; &lt;!-- identifier of the event we want to catch --&gt;
      &lt;observers&gt;
        &lt;sales_order_payment_capture_handler&gt; &lt;!-- identifier of the event handler --&gt;
          &lt;type&gt;model&lt;/type&gt; &lt;!-- class method call type; valid are model, object and singleton --&gt;
          &lt;class&gt;orderaudit/observer&lt;/class&gt; &lt;!-- observers class alias --&gt;
          &lt;method&gt;paymentCapture&lt;/method&gt;  &lt;!-- observer's method to be called --&gt;
          &lt;args&gt;&lt;/args&gt; &lt;!-- additional arguments passed to observer --&gt;
        &lt;/sales_order_payment_capture_handler&gt;
      &lt;/observers&gt;
    &lt;/sales_order_payment_capture&gt;
    &lt;sales_order_creditmemo_refund&gt; &lt;!-- identifier of the event we want to catch --&gt;
      &lt;observers&gt;
        &lt;sales_order_creditmemo_refund_handler&gt; &lt;!-- identifier of the event handler --&gt;
          &lt;type&gt;model&lt;/type&gt; &lt;!-- class method call type; valid are model, object and singleton --&gt;
          &lt;class&gt;orderaudit/observer&lt;/class&gt; &lt;!-- observers class alias --&gt;
          &lt;method&gt;creditmemoRefund&lt;/method&gt;  &lt;!-- observer's method to be called --&gt;
          &lt;args&gt;&lt;/args&gt; &lt;!-- additional arguments passed to observer --&gt;
        &lt;/sales_order_creditmemo_refund_handler&gt;
      &lt;/observers&gt;
    &lt;/sales_order_creditmemo_refund&gt;
  &lt;/events&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>Observer.php
      class Avi_OrderAudit_Model_Observer
      {</p>
  
  <pre><code>    public function orderPlaced(Varien_Event_Observer $observer)
      {
          if (Mage::getSingleton('admin/session')-&gt;isLoggedIn()) {
          //if admin
              $order = $observer-&gt;getEvent()-&gt;getOrder();
              $user = Mage::getSingleton('admin/session');
              $username = $user-&gt;getUser()-&gt;getUsername();
              $comment = "Order placed by &lt;strong&gt;".$username."&lt;/strong&gt;";
              $order-&gt;addStatusHistoryComment($comment)
                  -&gt;setIsVisibleOnFront(false)
                  -&gt;setIsCustomerNotified(false);
          }
          else {
          //placed by customer online
              $order = $observer-&gt;getEvent()-&gt;getOrder();
              $order-&gt;addStatusHistoryComment('Order placed online by customer')
                  -&gt;setIsVisibleOnFront(false)
                  -&gt;setIsCustomerNotified(false);
          }
      }
  
      public function paymentCapture(Varien_Event_Observer $observer)
      {
          $invoice = $observer-&gt;getEvent()-&gt;getInvoice();
          $order = $invoice-&gt;getOrder();
          $user = Mage::getSingleton('admin/session');
          $username = $user-&gt;getUser()-&gt;getUsername();
          $comment = "Payment captured by &lt;strong&gt;".$username."&lt;/strong&gt;";
          $order-&gt;addStatusHistoryComment($comment)
              -&gt;setIsVisibleOnFront(false)
              -&gt;setIsCustomerNotified(false);
      }
      public function creditmemoRefund(Varien_Event_Observer $observer)
      {
          $creditmemo = $observer-&gt;getEvent()-&gt;getCreditmemo();
          $order = $creditmemo-&gt;getOrder();
          $user = Mage::getSingleton('admin/session');
          $username = $user-&gt;getUser()-&gt;getUsername();
          $comment = "Refund by &lt;strong&gt;".$username."&lt;/strong&gt;";
          $order-&gt;addStatusHistoryComment($comment)
              -&gt;setIsVisibleOnFront(false)
              -&gt;setIsCustomerNotified(false);
  
      }
  }
  </code></pre>