Thursday , December 14 2017
Home >> All tutorial >> Magento Developers’ Guide – Part 10: Rewrite to modify a Magento controller

Magento Developers’ Guide – Part 10: Rewrite to modify a Magento controller

How to make a rewrite of a controller ? Because your module will not know where to search for your extended class…you have to make a require in your controller.

  1. require_once “Mage/Checkout/controllers/CartController.php”;
This gives you something like:
  1. require_once “Mage/Checkout/controllers/CartController.php”;
  2. class Pfay_Checkout_CartController extends Mage_Checkout_CartController
  3. {
  4.     # Rewrite of indexAction
  5.     public function indexAction() {
  6.         die(‘your method has been rewrited !!’);
  7.     }
  8. }

The require_once is important if your extends not work (because magento can not autoload that class)

Then your class is taken into account instead of the « classic » CartController of magento, set in the config.xml of your module:

  1. <?xml version=“1.0” encoding=“UTF-8”?>
  2. <config>
  3.    …
  4. <frontend>
  5. <routers>
  6.      <checkout>
  7.          <args>
  8.            <modules>
  9.              <Pfay_Checkout before=“Mage_Checkout”>Pfay_Checkout</Pfay_Checkout>
  10.            </modules>
  11.          </args>
  12.      </checkout>
  13.    </routers>
  14. </frontend>
  15. </config>

Now, it works 🙂

Tutorial by: pierrefay.com

We also contribute great content of Magento Download for FREE (all versions)

DON'T MISS THE CHANCE!

magento download

About Champ

One comment

  1. If I have to write for Magento Ajax cart pro, where I have to rewrite? Could you please mention the path?

Leave a Reply

Your email address will not be published. Required fields are marked *

Heap | Mobile and Web Analytics