Need Search & Discovery to include search of SKU

I need someone to help modify the Search & Discovery app to include looking in the SKU so that the predictive search can bring up all similar products.

Unfortunately, it doesnt look like Shopify exposes this as an option in the admin in most themes.

However, if you are a little comfortable editing code, you can modify your predictive search endpoint to include

&resources[options][fields]=title,product_type,variants.title,variants.sku

This is typically in your assets folder in the predictive-search.js file.

You should see something like:

fetch(

      `${routes.predictive_search_url}?q=${encodeURIComponent(

        searchTerm

      )}&section_id=predictive-search`,

      { signal: this.abortController.signal }

    )

      .then((response) => {

        if (!response.ok) {

          var error = new Error(response.status);

          this.close();

          throw error;

        }

You will want to add to that “&resources[options][fields]=variants.sku” like this:

 fetch(

      `${routes.predictive_search_url}?q=${encodeURIComponent(

        searchTerm

      )}&resources[options][fields]=title,product_type,vendor,variants.title,variants.sku&section_id=predictive-search`,

      { signal: this.abortController.signal }

    )

      .then((response) => {

        if (!response.ok) {

          var error = new Error(response.status);

          this.close();

          throw error;

        }

The defaults are title, product_type, vendor, variants.title but if you explicitly add another, you have to add the defaults as well.

Hope this helps. :slightly_smiling_face:

- Velvet