title: Trigger observer on Magento order status change events
body: <p>I need to automatically create an invoice on an order once it receives the <code>processing</code> status. Which event should be observed in my extension to achieve this?</p>
  
  <hr>
  
  <p>I'm trying but this code is not working, what can it be?</p>
  
  <p>.xml in etc/modules</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;config&gt;
  &lt;modules&gt;
      &lt;Atwix_Orderhook&gt;
          &lt;active&gt;true&lt;/active&gt;
          &lt;codePool&gt;community&lt;/codePool&gt;
      &lt;/Atwix_Orderhook&gt;
  &lt;/modules&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p>config.xml in app/code/...</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;config&gt;
  &lt;modules&gt;
      &lt;Atwix_Orderhook&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/Atwix_Orderhook&gt;
  &lt;/modules&gt;
  &lt;global&gt;
      &lt;models&gt;            
          &lt;orderhook&gt;
              &lt;class&gt;Atwix_Orderhook_Model&lt;/class&gt;
          &lt;/orderhook&gt;
      &lt;/models&gt;
      &lt;events&gt;
          &lt;sales_order_save_after&gt;
              &lt;observers&gt;
                  &lt;auto_invoice_order&gt;
                      &lt;type&gt;singleton&lt;/type&gt;
                      &lt;class&gt;Atwix_Orderhook_Model_Observer&lt;/class&gt;
                      &lt;method&gt;implementOrderStatus&lt;/method&gt;
                  &lt;/auto_invoice_order&gt;
              &lt;/observers&gt;
          &lt;/sales_order_save_after&gt;
      &lt;/events&gt;
  
  &lt;/global&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p>Oberver.php in app/code/...</p>
  
  <pre><code>&lt;?php
  class Atwix_Orderhook_Model_Observer 
  {
  public function implementOrderStatus($event)
  {
      $order = $event-&gt;getOrder();
  
      if ($order == 'processing') {
          if ($order-&gt;canInvoice())
              $this-&gt;_processOrderStatus($order);
      }
      return $this;
  }
                          private function _processOrderStatus($order)
                          {
                              $invoice = $order-&gt;prepareInvoice();
  
                              $invoice-&gt;register();
                              Mage::getModel('core/resource_transaction')
                                 -&gt;addObject($invoice)
                                 -&gt;addObject($invoice-&gt;getOrder())
                                 -&gt;save();
  
                              $invoice-&gt;sendEmail(false, '');
                              return true;
                          }
  }
  </code></pre>