“Altert : Shopify seems to have changed the way it used to work with the search page parameters. The solution below have stopped working.”

The default search bar of a shopify searches for all products from the store. In one of the project it was a requirement where along with the search bar there was collection dropdown, and it was few years back and that time i drop that feature mentioning client that it isn’t possible. But in this article i’m going to mention about the solution that allows to search products within a particular collection.

Before we jump into the solution lets talk about known search parameters. `q` & `type`.

`q` is a search text parameter which is a user input on search field. And `type` defines the search type. There are three search type page, article and product.  The type parameter can be any or combination (in case of combination separated by comma).

yourshopifystore.com/search?type=product,page&q={searchtext}

Until now there isn’t anything that separates products from specific collection. Now look at the url below

yourshopifystore.com/search/collections/{collection-handle}?type=product&q={searchtext}
yourshopifystore.com/search/collections/accessories?type=product&q=bag

In above example we have added /collections/{collection-handle} before sending parameters and this would filter products from collection in search result. The example demonstartes to search bag from accessories collection.

In header to activate the selected collection dropdown after reaching to search result page you can further add parameters like product_cat and supply collection handle like below.

yourshopifystore.com/search/collections/{collection-handle}?type=product&q={searchtext}&product_cat={collection-handle}
yourshopifystore.com/search/collections/accessories?type=product&q=bag&product_cat=accessories

Cheers.

 

 

Suman K.C

eCommerce Developer, writes about stuff related to eCommerce development. Currently based in Kathmandu, loves reading about startups & new technology, introvert nature, fond of traveling & playing futsal.

More Posts