Magento Overriding Block,Controller,Helper,Model and Observer


Model overriding

#Write Below code in config.xml of your Module#
<models>
 <sales>
    <rewrite>
       <order_pdf_abstract>
          Namespace_Sample_Model_Order_Pdf_Abstract
       </order_pdf_abstract>
       <order_pdf_invoice>
          Namespace_Sample_Model_Order_Pdf_Invoice
       </order_pdf_invoice>
       <order_pdf_creditmemo>
          Namespace_Sample_Model_Order_Pdf_Creditmemo
       </order_pdf_Creditmemo>
       <order_pdf_shipment>
          Namespace_Sample_Model_Order_Pdf_Shipment
       </order_pdf_shipment>
   </rewrite>
 </sales>
</models>

Block Overrides

#Write Below code in config.xml of your Module#
<blocks>
   <catalog>
     <rewrite>
       <product_view>
          Namespace_Sample_Block_Catalog_Product_View
       </product_view>
     </rewrite>
   </catalog>
</blocks>

Resource Model Overriding

#Write Below code in config.xml of your Module#
<models>
   <catalog>
     <rewrite>
        <resource_product_indexer_price_default>
              Namespace_Sample_Model_Catalog_Resource_Product_Indexer_Price_Default
        </resource_product_indexer_price_default>
     </rewrite>
   </catalog>
</models>

Observer

#Write Below code in config.xml of your Module#
<events>
      <EVENT_TO_HOOK>
         <observers>
            <module>
              <type>singleton</type>
              <class>namespace_sample_model_observer</class>
              <method>methodToCall</method>
            </module>
          </observers>
        </EVENT_TO_HOOK>
</events>

Observer Example:

<events>
     <sales_order_place_after>
       <observers>
           <feed_sales_order_observer>
               <type>singleton</type>
               <class>feedsales/order_observer</class>
               <method>export_new_order</method>
           </feed_sales_order_observer>
       </observers>
     </sales_order_place_after>
</events>

Controller Overriding
Way 1) #Write Below code in config.xml of your Module#

<global>
    <rewrite>
      <namespace_sample_checkout_controllers_cartcontroller>
         <from>
            <![CDATA[#^/checkout/controllers_cart/#]]>
         </from> <!-- Mage_Checkout_Controllers_CartController -->
         <to>
            /sample/checkout_controllers_cart/
         </to> <!-- Namespace_Sample_Checkout_Controllers_CartController -->
      </namespace_sample_checkout_controllers_cartcontroller>
    </rewrite>
</global>

Way 2) #Write Below code in config.xml of your Module#
 <frontend>
     <routers>
       <sample>
        <args>
          <modules>
           <Namespace_Sample before="Mage_Checkout">
              Namespace_Sample
           </Namespace_Sample>
          </modules>
       </args>
      </sample>
    </routers>
</frontend>

#Write Below line in your controller like given below#
<?php
require_once "Mage/Checkout/controllers/Controllers/CartController.php";
class Namespace_Sample_Checkout_Controllers_CartController extends Mage_Checkout_Controllers_CartController{

}
?>

Helper Overriding

#Write Below code in config.xml of your Module#
Mage_Checkout_Helper_Cart
<helpers>
    <checkout>
      <rewrite>
        <cart>
          Namespace_Sample_Helper_Checkout_Cart
        </cart>
      </rewrite>
    </checkout>
</helpers>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s