Question

I want to see search results in list mode by default in desktop, and see it on grid mode on mobile. What should I do? Right now I edited catalog search list.phtml to show list mode by default on search result page but on mobile, I see list mode too. I want to see grid mode on mobile.

Update from comment:

if ($block->getMode() == 'grid') {
    $viewMode = 'list';
    $image = 'category_page_list';
    $showDescription = false;
    $templateType = 
    \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
} else {
    $viewMode = 'grid';
    $image = 'category_page_grid';
    $showDescription = true;
    $templateType = 
    \Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
}

but it works on any device, can not seperate them for devices

Was it helpful?

Solution 2

https://marketplace.magento.com/eadesignro-module-mobiledetect.html

Finally, got this extension, it works well.

OTHER TIPS

  1. You can create a new theme having the parent as your current theme.
  2. Then set up the new theme as an exception for the mobile devices.
  3. In the new theme, you can override the list.phtml file and write your custom logic (or simply remove the code for the grid view. Keep the code for the list view only).

Update: Add an exception for mobile devices

  1. Go to Design >> Configuration and click on the row of the currently applied theme.
  2. Under Design Rule >> User Agent Rules, you will find Add New User Agent Rule button. Click on it to add the exception. Input the value of the Search String and select the theme as the exception.

Search strings are either normal strings or regular expressions (PCRE).

  1. Save the configuration and deploy the static content.

Theme Exception

I hope it makes sense.

Please let me know if you have any related question.

Add "mobile" in search string and select any template you want to use for mobile, and its done. For all mobile devices automatically those templates will be taken. options

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