2

My handle is av_paginator_result

It's for ajax request and it should echo some short result.

<layout version="0.1.0">
<av_paginator_result>
        <block type="catalog/product_list" name="root" output="toHtml" template="av/paginator/catalog/product/list.phtml">
            <block type="catalog/product_list_toolbar" name="product_list_toolbar">
                <block type="page/html_pager" name="product_list_toolbar_pager"/>
            </block>
            <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
            <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
            <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
            <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
            <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
            <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
        </block>
    </av_paginator_result>
</layout>

I created an observer (controller_action_layout_generate_blocks_after) which is catched by post request:

$moduleName = Mage::app()->getRequest()->getModuleName();

        if (Mage::app()->getRequest()->isPost() && in_array($moduleName, array('catalogsearch', 'catalog')))
        {
            $layout =  Mage::app()->getLayout();
            $update = $layout->getUpdate();

            Mage::app()->getLayout()->getUpdate()->resetHandles();

            $update->load('av_paginator_result');
            $layout->generateXml();
            $layout->generateBlocks();

            $products = array();

            $page = Mage::app()->getRequest()->getPost('page', 1);

            $root = $layout->getBlock('root');

            $product_list_toolbar = $root->getToolbarBlockName();

            if ($toolBar = $layout->getBlock($product_list_toolbar))
            {
                Mage::app()->getRequest()
                    ->setParam($toolBar->getPageVarName(), (int) $page);

                $output = $layout->getOutput();
                print $output;
            }
            exit;
        }

All these codes work good but if I turn Layout Cache on it doesn't. It always try to generate whole category page, not just a part. Why?

1

Just a guess but I think there is a cache key which has the same name, so when the cache gets filled, the wrong content is loaded for your request.

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.