0

I am trying to extend an extensions controller so I can make changes without hacking about with the vendor's code.

The extension's controller which I can trying to extend is

/app/community/Rewardpoints/controllers/IndexController.php

and it looks like the following

class Rewardpoints_IndexController extends Mage_Core_Controller_Front_Action
{
   public function quotationAction(){

   }
}

This is what I have so far

1) Enable the module by creating /app/etc/modules/Namespace_ModuleName.xml

<config>
    <modules>
        <Namespace_ModuleName>
            <active>true</active>
            <codePool>local</codePool>
             <depends>
              <Rewardpoints/>
             </depends>
        </Namespace_ModuleName>
    </modules>
</config>

2) Set up the config /app/code/local/Namespace/ModuleName/etc/config.xml

 <?xml version="1.0"?> 
 <config>  
      <frontend>
    <routers>
        <rewardpoints>
            <args>
                <modules>
                    <Namespace_ModuleName before="Rewardpoints">Namespace_ModuleName</Namespace_ModuleName>
                </modules>
            </args>
        </rewardpoints>
    </routers>
</frontend>
</config>

3) Set up the new control- /app/code/local/Namespace/ModuleName/controller.php

   class Namespace_ModuleName_IndexController extends Rewardpoints_IndexController
   {
        public function quotationAction()
        {
            echo 'test';
            exit;
        }
    }

The error that I am getting though is Fatal error: Class 'Rewardpoints_IndexController' not found in /app/code/local/Namespace/ModuleName/controllers/IndexController.php on line 4

1 Answer 1

3

You should include the file containing the controller you want to extend, because they are not auto-loaded for controllers. Something like :

<?php
include_once 'Rewardpoints/controllers/IndexController.php';
class Namespace_ModuleName_IndexController extends Rewardpoints_IndexController
{
    public function quotationAction()
    {
        echo 'test';
        exit;
    }
}

Your original module doesn't have package name though ? It's not very standard.

2
  • Thanks that has worked. Yes I thought the same as I have never seen any extensions packaged like that before. The extension is j2t-design.net/j2t-points-rewards.html
    – Goose84
    Commented Jun 5, 2015 at 9:45
  • I'm not sure how this works without a namespace. But The Magento Way of requiring a controller is actually require_once Mage::getConfig()->getModuleDir('controllers', 'RewardPoints') . '/IndexController.php'; Commented Jun 5, 2015 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.