0

A bit new to Magento but need to do next thing:

  • Hierarchial catalog(HC) [Category > Subcategory('s) > Products]

I found on the web that i can rewrite app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/list.phtml
to actually gain what I need. But turns out that Magento_CatalogSearch using same file from Magento_Catalog to show results.

Is there some switch or variable where i can spot when search is called?
Or some other way to reload how HC loads?

1 Answer 1

2
  1. Override vendor\magento\module-catalog-search\view\frontend\layout\catalogsearch_result_index.xml to your theme inside app/design/frontend/Vendor/theme/Magento_CatalogSearch/layout and add below catalogsearch_result_index.xml in layout folder:

     <?xml version="1.0"?><page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
     <body>
         <attribute name="class" value="page-products"/>
         <referenceContainer name="content">
             <block class="Magento\CatalogSearch\Block\Result" name="search.result" template="Magento_CatalogSearch::result.phtml">
                 <block class="Magento\CatalogSearch\Block\SearchResult\ListProduct" name="search_result_list" template="Magento_CatalogSearch::product/search-list.phtml">
                     <arguments>
                         <!-- If argument's position depends on image size changeable in VDE:
                         positions:list-secondary,grid-secondary,list-actions,grid-actions,list-primary,grid-primary
                     -->
                         <argument name="positioned" xsi:type="string">positions:list-secondary</argument>
                         <argument name="viewModel" xsi:type="object">Magento\Catalog\ViewModel\Product\OptionsData</argument>
                     </arguments>
                     <block class="Magento\Catalog\Block\Product\ProductList\Toolbar" name="product_list_toolbar" template="Magento_Catalog::product/list/toolbar.phtml">
                         <block class="Magento\Theme\Block\Html\Pager" name="product_list_toolbar_pager"/>
                     </block>
                     <action method="setToolbarBlockName">
                         <argument name="name" xsi:type="string">product_list_toolbar</argument>
                     </action>
                     <block class="Magento\Framework\View\Element\RendererList" name="category.product.type.details.renderers" as="details.renderers">
                         <block class="Magento\Framework\View\Element\Template" name="category.product.type.details.renderers.default" as="default"/>
                     </block>
                     <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="catalogsearch.product.addto" as="addto">
                         <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                                name="catalogsearch.product.addto.compare" as="compare"
                                template="Magento_Catalog::product/list/addto/compare.phtml"/>
                     </block>
                 </block>
                 <action method="setListOrders"/>
                 <action method="setListModes"/>
                 <action method="setListCollection"/>
             </block>
             <block class="Magento\Framework\View\Element\Template" name="search.search_terms_log" template="Magento_CatalogSearch::search_terms_log.phtml">
                 <arguments>
                     <argument name="search_terms_log" xsi:type="object">Magento\CatalogSearch\Block\SearchTermsLog</argument>
                 </arguments>
             </block>
         </referenceContainer>
     </body>
    
  2. Copy and rename the file app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/list.phtml to app/design/frontend/Vendor/theme/Magento_CatalogSearch/templates/product/search-list.phtml

We have not tested it but it will work. OR in list.phtml try with below code :

print_r($this->getRequest()->getFullActionName());

if you get return like : catalogsearch_result_index in the search page. then add a condition for search result as below:

if($this->getRequest()->getFullActionName() == 'catalogsearch_result_index '){
// do your stuff
}
3
  • @saurebh-dwivedi, it's not working for me... any other solution? Commented Dec 15, 2022 at 16:05
  • I have updated in answer please check if it helps you. Commented Dec 15, 2022 at 17:08
  • @saurebh-dwivedi, Yes thats it... at least i can work with it. Commented Dec 15, 2022 at 18:53

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.