1

Synopsis

I am trying to extend an admin controller of a module, however the frontend router and adminhtml router share the same frontname. I've tried so many things and none of them are working.

Extension router example

 <admin>
    <routers>
        <AdvancedStock>
            <use>admin</use>
            <args>
                <module>MDN_AdvancedStock</module>
                <frontName>AdvancedStock</frontName>
            </args>
        </AdvancedStock>
    </routers>
</admin>

... snip ...

<frontend>
    <routers>
        <AdvancedStock>
            <use>standard</use>
            <args>
                <module>MDN_AdvancedStock</module>
                <frontName>AdvancedStock</frontName>
            </args>
        </AdvancedStock>
    </routers>
</frontend>

Attempts

Attempt 1

<admin>
    <routers>
        <Vendor_AdvancedStock>
            <args>
                <modules>
                    <Vendor_AdvancedStock before="MDN_AdvancedStock">Vendor_AdvancedStock</Vendor_AdvancedStock>
                </modules>
            </args>
        </Vendor_AdvancedStock>
    </routers>
</admin>

Attempt 2

<frontend>
    <routers>
        <Vendor_AdvancedStock>
            <args>
                <modules>
                    <Vendor_AdvancedStock before="MDN_AdvancedStock">Vendor_AdvancedStock</Vendor_AdvancedStock>
                </modules>
            </args>
        </Vendor_AdvancedStock>
    </routers>
</frontend>

Attempt 3

This was attempt 1 and attempt 2 combined.

Attempt 4

<frontend>
    <routers>
        <AdvancedStock> <!-- this is the original vendors tag -->
            <args>
                <modules>
                    <Vendor_AdvancedStock before="MDN_AdvancedStock">Vendor_AdvancedStock</Vendor_AdvancedStock>
                </modules>
            </args>
        </AdvancedStock>
    </routers>
</frontend>

I have even added the depends tag and tried the above attempts with no success.

2
  • which controller that you need to extend? admin side controller or frontend side controller ? Commented Aug 7, 2014 at 13:15
  • I need to extend an admin controller, also I noticed adminhtml was wrong in my example and so i've corrected it.
    – Ash
    Commented Aug 7, 2014 at 13:16

3 Answers 3

3

Try this:

<admin>
    <routers>
        <advancedstock> <!-- put there the router key of the original module -->
            <args>
                <modules>
                    <Vendor_AdvancedStock before="MDN_AdvancedStock">Vendor_AdvancedStock</Vendor_AdvancedStock>
                </modules>
            </args>
        </advancedstock>
    </routers>
</admin>

Then place your controller inside Vendor/AdvancedStock/controllers and make sure it's called the same as the original controller.

12
  • This didn't seem to work; the extension class is: MDN_AdvancedStock_ProductController and my class is Vendor_AdvancedStock_Adminhtml_ProductController in ./local/Vendor/AdvancedStock/controllers/Adminhtml/ProductController.php
    – Ash
    Commented Aug 7, 2014 at 13:24
  • @Ash : Most probably this controller would be a frontend controller. Are you sure it is an admin controller ? Can you provide the class that extend this controller here ? lcoation and its name confuses me ! Commented Aug 7, 2014 at 13:27
  • @Ash. You mean there is a ProductController that is used for admin and it is not inside an Adminhtml folder in the extension?
    – Marius
    Commented Aug 7, 2014 at 13:27
  • 2
    Ok, then try to lose the _Adminhtml in the code above and move your controller file also inside Vendor/AdvancedStock/controllers/ProductController.php. Damn, that's a badly written extension.
    – Marius
    Commented Aug 7, 2014 at 13:29
  • 1
    @Ash. I will edit the answer to remain here for posterity
    – Marius
    Commented Aug 7, 2014 at 13:39
1
<admin>
        <routers>
            <advancedstock> <!-- assume advancedstock is routers of  MDN_AdvancedStock   -->
                <args>
                    <modules>
                        <Vendor_AdvancedStock before="MDN_AdvancedStock">Vendor_AdvancedStock_Adminhtml</Vendor_AdvancedStock>
                    </modules>
                </args>
            </advancedstock>
        </routers>
    </admin>

Vendor_AdvancedStock_Adminhtml is admincontroller dir of module Vendor_AdvancedStock

6
  • This is less informative as to what Marius suggested :S
    – Ash
    Commented Aug 7, 2014 at 13:27
  • This answer is extremely similar as the one Marius posted. Is this a coincidence or is a plain copy of the other answer?
    – mbalparda
    Commented Aug 7, 2014 at 13:54
  • My answer and Marius answer have posted concurrent :)
    – Amit Bera
    Commented Aug 7, 2014 at 13:55
  • Not true. They were separated by quite some time, like 15 mins.
    – mbalparda
    Commented Aug 7, 2014 at 14:41
  • dear mbalparda.. i have put own answer....
    – Amit Bera
    Commented Aug 7, 2014 at 14:42
0

Ya I was waiting for marius to answer this question. He did it as I expected. I need to mention one more thing along with his answer. You need to call that "bad controller" just above your controller definition. That is

File :Vendor/AdvancedStock/controllers/ProductController.php

<?php    
require_once(Mage::getModuleDir('controllers','MDN_AdvancedStock').DS.'ProductController.php');
class Vendor_AdvancedStock_ProductController extends MDN_AdvancedStock_ProductController
{
     // some code
}

I told so because, as per my knowledge magento will not include the class that you are going to rewrite, if that class stands for a controller. For block rewrite, helper rewrite you may not require this step. Since magento will do that job for us.

2
  • I sort of excluded this as I assumed people knew - but for anyone here that doesn't will find it useful :)
    – Ash
    Commented Aug 7, 2014 at 13:39
  • Yes you are right. I am sure that, this point will help someone later. So I will request marius to mention my answer also . Commented Aug 7, 2014 at 13:43

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.