#magento #xml

Magento – Extending Core Classess for Models, Blocks & Helpers – cheatsheet

General Rules for rewriting Classes in Magento 1.7 (1.8):

<config>
  <global>
  <!-- models / helpers / resources / etc...  -->
    <models> 
      <!-- Module name -->
      <module> 
        <rewrite>
         <!-- the tag name is the Model / Block/ Helper to be rewritten -->
          <model>
            Namespace_Module_Model_Sales_Order_Item
          </model> 

        </rewrite>
      </module>
    </models>
  </global>
</config>

1. Example – Rewriting Model Class for the class Mage_Core_Model_Session:

The path to the model : /app/code/core/Mage/Core/Models/Session.php

<config>
  <global>
    <models> <!-- We are rewriting a Model Class -->
      <core> <!-- "core" - because the session Model is in the Core module -->
      <rewrite>
        <session> <!-- "session" - because its the Model name -->
          <!-- The name of the class, 
               that would rewrite the "Mage_Core_Model_Session" -->
          Namespace_Module_Model_Session 
        </session>
      </rewrite>
      </core>
    </models>
  </global>
</config>

2. Example – Rewriting the class Mage_Sales_Block_Order_Totals

The path to the block class : /app/code/core/Mage/Sales/Block/Totals.php

<config> 
  <global> 
    <blocks> 
    <!-- We are rewriting a Block Class -->
      <!-- "sales" - because this Block is in that module --> 
      <sales><rewrite> 
        <!-- "order_totals" - because its the Block name -->
        <order_totals> 
          <!-- The name of the class, that would rewrite the 
                         "Mage_Sales_Block_Order_Totals" --> 
          Namespace_Module 
         </order_totals> 
      </rewrite></sales> 
    </blocks> 
  </global> 
</config>