Monday , August 21 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:

Ready to foster your knowledge with MAGENTO 2 BASIC GUIDE

The new Order Success combo with Magento 2 Inventory Management, Magento 2 Order Fulfillment, Magento 2 Dropship, Magento 2 Barcode Management and Magento 2 Purchase Management

Is your site still a mess and Magento extensions are not enough to save your site? Save your site with Magento Web Development Services now

magento services

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 *