Filter Catalog search results and display it as 2 separate collection in a single page

magento.stackexchange https://magento.stackexchange.com/questions/4808

  •  16-10-2019
  •  | 
  •  

Question

Is it possible to filter the search results by attribute set and display the results as 2 separate collections.Thanks in advance.

EDIT: I tried this

<catalogsearch_result_index translate="label">
        <label>Quick Search Form</label>
        <reference name="root">
            <action method="setTemplate"><template>page/3columns.phtml</template></action>
        </reference>
        <reference name="left">
            <block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
        </reference>
        <reference name="content">
            <block type="catalogsearch/result" name="search.result" template="catalogsearch/result.phtml">
                <block type="catalog/product_list" name="search_result_list" template="catalog/product/list.phtml">
                    <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                        <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>
                <action method="setListOrders"/>
                <action method="setListModes"/>
                <action method="setListCollection"/>
            </block>
        </reference>
        <reference name="content">

                <block type="catalog/product_list" name="search_result_list_new" template="catalog/product/listnew.phtml">
                    <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
                        <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>
                <action method="setListOrders"/>
                <action method="setListModes"/>
                <action method="setListCollection"/>

        </reference>
    </catalogsearch_result_index>

listnew.phtml

$_productCollection = clone $this->getLoadedProductCollection();
$_productCollection->clear()
                   ->addAttributeToFilter('attribute_set _id',array('neq'=>1))
                   ->load();

I used the above code.i got the search results but the sortby relevance is missing .Is there a better method to achieve this

Was it helpful?

Solution

Displaying two product collections on one page is certainly possible, though you will have to take care of a few things that the pager works correctly.

First, both toolbar and both pager blocks need to have different names, otherwise both will use the same block instance, rendering the same html.

Then you will need to create your own toolbar class which extends from catalog/product_list_toolbar for the second list, and set different values for $_pageVarName, $_orderVarName, $_directionVarName, $_modeVarName and $_limitVarName.
Alternatively you could hack something with reflection to modify the protected properties, but I advise agains that. If you use the same toolbar class for both toolbar blocks, they won't know which one should apply a given sorting or ordering. Both will always use the same values, unless they use different HTTP query parameter names.

Thats all, otherwise you should be all good.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top