How to set the list grid to be the default preview when product/products are displayed using the search bar?
-
Are you saying that you want a different default mode (grid/list) on search result pages than in the catalog pages?– zigojackoJul 16, 2015 at 11:47
-
yes for example, when a customer is browsing through my shop and he observes products to see the products as grid, but when a customer is searching for a product/products i want the product to appear as list.– vasilisdmrJul 16, 2015 at 11:50
-
Answered - hope it helps.– zigojackoJul 16, 2015 at 12:25
-
Could you please give me an extension for magento 2.1.9 for this title?– MGPMApr 26, 2018 at 9:11
2 Answers
<catalog_category_layered>
<reference name="product_list_toolbar">
<action method="setData">
<key>_current_grid_mode</key>
<value>grid</value>
</action>
</reference>
</catalog_category_layered>
1. Making catalogsearch use it's own template
Duplicate list.phtml
like for example, listsearch.phtml
.
Then you can either completely remove the list mode section if you don't want customers to be able to switch between modes or modify it to set the default...
Within listsearch.phtml
, at the top of the page (just above <div class="category-products">
), specify the default mode with:-
$this->getChild('toolbar')->setCurrentMode('grid');
Then make the catalog search use this new template file:-
<block type="catalogsearch/result" name="search.result" template="catalogsearch/result.phtml">
<block type="catalog/product_list" name="search_result_list" template="catalog/product/listsearch.phtml">
<!-- etc etc -->
</block>
</block>
2. Declaring the default mode via XML
In your local.xml
, specify the config values for the product_list_toolbar
like:-
<catalogsearch_result_index translate="label">
<reference name="product_list_toolbar">
<action method="setData">
<key>_current_grid_mode</key>
<value>grid</value>
</action>
</reference>
</catalogsearch_result_index>
Either of these methods should work depending on the extend of how much you wish to customise the product listings in the catalog search results differently from the main catalog.