title: Magento - How to trigger event (change user group) after purchasing a specific product
body: <p>My question is how to trigger an action after a successful order (with ID 11)?</p>
  
  <p>I read from previous questions that I need to create an observer for <code>checkout_onepage_controller_success_action</code> but not much is explained after that.</p>
  
  <p>Below is the code that (from the same previous question) I used to change the product:</p>
  
  <pre><code>$special_cat = 11; // Special product category
  $customerId = Mage::getSingleton('customer/session')-&gt;getCustomerId();
  $lastOrderId = Mage::getSingleton('checkout/session')-&gt;getLastOrderId();
  $order = Mage::getSingleton('sales/order'); 
  $order-&gt;load($lastOrderId);
  $allitems = $order-&gt;getAllItems();
  foreach($allitems as $item)
  {
      $product = Mage::getModel('catalog/product')-&gt;load($item-&gt;getProductId());
      $categoryIds = $product-&gt;getCategoryIds();
      if (in_array($special_cat, $categoryIds)) {
          $mem_group_id = $item-&gt;getSku();  // $item-&gt;getSku() is customer group name
          $customer_detail = Mage::getSingleton('customer/session')-&gt;getCustomer();
          $customer_detail-&gt;setGroupId($mem_group_id);
          $customer_detail-&gt;save();
      }
  }
  </code></pre>
  
  <p>Do I need to create an extension for this or do I need to edit the core files? Where should I create the Observer?</p>