1

I want to create Ajax layerd navigation... So for that I want to override category controller.. But I try a lots. but i don't know why this not overriding....

my config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Deepak_Ajaxdeep>
        <version>0.1.0</version>
    </Deepak_Ajaxdeep>
</modules>

<frontend>
   <routers>
            <ajaxdeep>
                <use>standard</use>
                <args>
                    <module>Deepak_Ajaxdeep</module>
                    <frontName>ajaxdeep</frontName>
                </args>
            </ajaxdeep>
            <catalog>
                <args>
                    <modules>
                        <Deepak_Ajaxdeep before="Mage_Catalog">Deepak_Ajaxdeep_Catalog</Deepak_Ajaxdeep>
                    </modules>
                </args>
            </catalog>
            <catalogsearch>
                <args>
                    <modules>
                        <Deepak_Ajaxdeep before="Mage_CatalogSearch">Deepak_Ajaxdeep_CatalogSearch</Deepak_Ajaxdeep>
                    </modules>
                </args>
            </catalogsearch>
        </routers>
</frontend>
</config>

controllers

require_once('app/code/core/Mage/Catalog/controllers/CategoryController.php');
class Deepak_Ajaxdeep_Catalog_CategoryController extends Mage_Catalog_CategoryController
{

    public function viewAction()
    {
        echo 'test';exit;
        if($this->getRequest()->isXmlHttpRequest() && (!$this->getRequest()->getParam("fullpageajax") || $this->getRequest()->getParam("ajaxcatalog"))){ //Check if it was an AJAX request
            $response = array();

            if ($category = $this->_initCatagory()) {
                $design = Mage::getSingleton('catalog/design');
                $settings = $design->getDesignSettings($category);

                // apply custom design
                if ($settings->getCustomDesign()) {
                    $design->applyCustomDesign($settings->getCustomDesign());
                }

                Mage::getSingleton('catalog/session')->setLastViewedCategoryId($category->getId());

                $update = $this->getLayout()->getUpdate();
                $update->addHandle('default');

                if (!$category->hasChildren()) {
                    $update->addHandle('catalog_category_layered_nochildren');
                }

                $this->addActionLayoutHandles();
                $update->addHandle($category->getLayoutUpdateHandle());
                $update->addHandle('CATEGORY_' . $category->getId());
                $this->loadLayoutUpdates();

                // apply custom layout update once layout is loaded
                if ($layoutUpdates = $settings->getLayoutUpdates()) {
                    if (is_array($layoutUpdates)) {
                        foreach($layoutUpdates as $layoutUpdate) {
                            $update->addUpdate($layoutUpdate);
                        }
                    }
                }

            $this->generateLayoutXml()->generateLayoutBlocks(); //Generate new blocks
            $viewpanel = $this->getLayout()->getBlock('catalog.leftnav')->toHtml();
            $productlist = $this->getLayout()->getBlock('product_list')->toHtml(); // Generate product list
            $response['status'] = 'SUCCESS';
            $response['viewpanel']=$viewpanel;
            $response['productlist'] = $productlist;

            // apply custom layout (page) template once the blocks are generated
            }elseif (!$this->getResponse()->isRedirect()) {
                $this->_forward('noRoute');
                $response['status'] = 'FAILURE';
            }
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
            return;
        }

        if ($category = $this->_initCatagory()) {
            $design = Mage::getSingleton('catalog/design');
            $settings = $design->getDesignSettings($category);

            // apply custom design
            if ($settings->getCustomDesign()) {
                $design->applyCustomDesign($settings->getCustomDesign());
            }

            Mage::getSingleton('catalog/session')->setLastViewedCategoryId($category->getId());

            $update = $this->getLayout()->getUpdate();
            $update->addHandle('default');

            if (!$category->hasChildren()) {
                $update->addHandle('catalog_category_layered_nochildren');
            }

            $this->addActionLayoutHandles();
            $update->addHandle($category->getLayoutUpdateHandle());
            $update->addHandle('CATEGORY_' . $category->getId());
            $this->loadLayoutUpdates();

            // apply custom layout update once layout is loaded
            if ($layoutUpdates = $settings->getLayoutUpdates()) {
                if (is_array($layoutUpdates)) {
                    foreach($layoutUpdates as $layoutUpdate) {
                        $update->addUpdate($layoutUpdate);
                    }
                }
            }

            $this->generateLayoutXml()->generateLayoutBlocks();
            // apply custom layout (page) template once the blocks are generated
            if ($settings->getPageLayout()) {
                $this->getLayout()->helper('page/layout')->applyTemplate($settings->getPageLayout());
            }

            if ($root = $this->getLayout()->getBlock('root')) {
                $root->addBodyClass('categorypath-' . $category->getUrlPath())
                ->addBodyClass('category-' . $category->getUrlKey());
            }

            $this->_initLayoutMessages('catalog/session');
            $this->_initLayoutMessages('checkout/session');
            $this->renderLayout();
        }elseif (!$this->getResponse()->isRedirect()) {
            $this->_forward('noRoute');
        }
    }

}

1 Answer 1

1

There some change require in your code:

No1: Mage_Catalog module CategoryController properly not included.

You need to include this file at your override controller in magento way.

require_once('app/code/core/Mage/Catalog/controllers/CategoryController.php');

Is should be

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

Also you need to create module config file Deepak_Ajaxdeep.xml at app/etc/modules

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.