1

I'm trying to add an action "sample" to the product controller which was going fine. I wanted the url domain.com/catalog/product/sample/sku/{sku}/ so here's what I did:

  1. Added file Org_Catalog.xml in app/etc/modules/

    <?xml version="1.0"?>
    <config>
      <modules>
        <Org_Catalog>
          <active>true</active>
          <codePool>local</codePool>
        </Org_Catalog>
      </modules>
    </config>
    
  2. Added config.xml in app/code/local/Org/Catalog/etc/

    <?xml version="1.0"?>
    
    <config>
    <modules>
        <Org_Catalog>
            <version>0.1.0</version>
        </Org_Catalog>
    </modules>   
    
    <frontend>
        <routers>
            <Catalog>
                <use>standard</use>
                <args>
                    <module before="Mage_Catalog">Org_Catalog</module>
                    <frontName>catalog</frontName>
                </args>
            </Catalog>
        </routers>
    </frontend>    
    </config>
    
  3. Added ProductController.php in app/code/local/Org/Catalog/controllers/

    <?php
    require_once 'Mage/Catalog/controllers/ProductController.php';
    
     class Org_Catalog_ProductController extends Mage_Catalog_ProductController{
    
        public function sampleAction(){
            Mage::Log("reached sample action");
        }
    }
    

Everything here was working fine but then I noticed the category page has stopped working. All category pages now go to 404 pages. The url translates to domain.com/catalog/category/view/id/4 for one of the category. I didn't touch any of the CategoryController.php files or anything else. I can't tell why it's not working.

Edit: Just for a try, I added CategoryController.php in app/code/local/Org/Catalog/controllers and filled it with

<?php

require_once(Mage::getModuleDir('controllers','Mage_Catalog').DS.'CategoryController.php');

class Org_Catalog_CategoryController extends Mage_Catalog_CategoryController{

}

This made the category page load. It seems that what I did has completely disabled the original catalog module, not extended it. Magento is not looking for the files in the core even though it didn't find it in the local folder. I just wanted to add an action so is there another way of doing it?

0

The reason that anything with a catalog controller would be dying based on your code is the incorrect path being used for require_once. You need to use a path relative to the Magento install root. Try this:

require_once Mage::getModuleDir('controllers', 'Mage_Catalog').DS.'ProductController.php

I have just created a working example. It works for me at http://local.datafeed.com/catalog/product/sample/

app/code/local/Org/Catalog/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Org_Catalog>
            <version>0.1.0</version>
        </Org_Catalog>
    </modules>
    <frontend>
        <routers>
            <catalog>
                <args>
                    <modules>
                        <Org_Catalog before="Mage_Catalog">Org_Catalog</Org_Catalog>
                    </modules>
                </args>
            </catalog>
        </routers>
    </frontend>
</config>

app/code/local/Org/Catalog/controllers/ProductController.php

<?php

require_once Mage::getModuleDir('controllers', 'Mage_Catalog').DS.'ProductController.php';
class Org_Catalog_ProductController extends Mage_Catalog_ProductController {

    public function sampleAction()
    {
        echo "reached sample action!";
    }

}

enter image description here

  • It's likely to be one of your problems so I would keep it. Have you turned on error reporting? – Shawn Abramson Oct 16 '16 at 14:14
  • Yes, I'm keeping the version you suggested. Also take a look at the updated question – VeeK Oct 16 '16 at 14:23
  • Try <module before="Mage_Catalog_Product">Org_Catalog_Product</module> – Shawn Abramson Oct 16 '16 at 14:50
  • Also if you have not yet uncommented the ini_set display errors line inside index.php you should go ahead and do that bc it may very well reveal the error. – Shawn Abramson Oct 16 '16 at 14:54
  • Error reporting is on. I didn't get any errors. Anyway, I ended up making it a seperate module instead of an extension of core. The only difference is of the url. I can live with that. If anyone else encounters a similar problem and the above comment helps out, let us know. – VeeK Oct 16 '16 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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