0

in my template for load category left block after load page by ajax use this method

    public function viewAction()
{

    if($this->getRequest()->isXmlHttpRequest() && (!$this->getRequest()->getParam("fullpageajax") || $this->getRequest()->getParam("ajaxcatalog") || $this->getRequest()->getParam("infinite"))){ //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();
        ///error is here

        $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');
    }
}

but this line create error

            $viewpanel =  $this->getLayout()->getBlock('catalog.leftnav')->toHtml();

is there any way to replace this part with other same code ?

6
  • Was something wrong with formating edits?
    – sv3n
    Jun 6 '17 at 19:19
  • is it impotent that a statement started with Load or load ...edit just for L or l ??? Jun 7 '17 at 5:09
  • Also corrected some line intents for better readability. :) If you have found a soulution please accept your own answer.
    – sv3n
    Jun 7 '17 at 6:15
  • i think i can not accept my answer ...is it imposible ? @s Jun 7 '17 at 10:29
  • It is possible ... maybe not enough reputation yet?
    – sv3n
    Jun 7 '17 at 10:36
0

i found answer and put it here for other developer

$this->getLayout()->getBlock('catalog.leftnav')->setTemplate('catalog/navigation/left.phtml')->toHtml();

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.