Redirect search result to page or collection instead of "no products found" in search bar Empire the

Is there a way to redirect a customer who searches for a particular product to a collection/page instead of returning a result of “no product found”?

We no longer stock a particular vendor’s (Carbsmart) products and have replaced those with 2 different vendors offering similar products, however, I still have a lot of customers searching my site for the old vendor.

I have created a collection (https://www.caringcandies.com/collections/carbsmart), where I explain that we no longer stock the Carbsmart range, but we can offer them the alternative products.

They either search on “carbsmart” or “carb smart” and I need both of those options to direct them to the Carbsmart collection page (https://www.caringcandies.com/collections/carbsmart) so they can see the alternate products.

Hello Denise, I don’t have a great answer for this one; and while you’re probably not looking for an app to do this one thing, I wanted to suggest Argoid for Search, just in case - https://apps.shopify.com/Argoid. It offers smart search, and can handle ‘No results found’ in multiple ways. You might want to give it a try. Thanks.

2 Likes

Edit main-search.liquid and add the below code above “{%- if search.performed and search.results.size > 0 -%}”

|



|
| - |

Actually use this as you can include the multiple criteria in the “searchCarbsmartArr” array as you requested. Just add more values separated by a comma wrapped in quotes. If you need to set this for something else just make a new array and copy the if statement.

| |
| - |

Good morning. Thanks for the reply. I cannot find a file called main-search.liquid. The closest I am finding are static-search.liquid and dynamic-search.liquid, and search.header.liquid.

Static-search.liquid contains the following but I am unsure as to where to put the script:

{% assign enable_content = section.settings.enable_search_articles_pages %}

{% assign paginate_by = section.settings.results_per_page_range %}

{% paginate search.results by paginate_by %}

{% comment %}
Calculate number of results by type.
{% endcomment %}
{% assign product_count = 0 %}
{% assign article_count = 0 %}
{% assign page_count = 0 %}

{% assign page_title = ‘general.accessibility.search’ | t %}
{% assign total_result_count = search.results.size %}
{% if total_result_count > 0 %}
{% capture sanitized_terms %}
{%
render ‘search-sanitizer’,
search_terms: search.terms
%}
{% endcapture %}

{% assign sanitized_terms = sanitized_terms | strip %}
{% assign page_title = ‘general.accessibility.search_results’ | t: terms: sanitized_terms %}
{% endif %}

{% for item in search.results %}
{% if item.object_type == ‘product’ %}
{% assign product_count = product_count | plus: 1 %}
{% endif %}

{% if enable_content %}
{% if item.object_type == ‘article’ %}
{% assign article_count = article_count | plus: 1 %}
{% endif %}

{% if item.object_type == ‘page’ %}
{% assign page_count = page_count | plus: 1 %}
{% endif %}
{% endif %}
{% endfor %}

{% comment %}
Calculate the number of result types.
{% endcomment %}
{% assign type_count = 0 %}
{% if product_count > 0 %}{% assign type_count = type_count | plus: 1 %}{% endif %}
{% if article_count > 0 %}{% assign type_count = type_count | plus: 1 %}{% endif %}
{% if page_count > 0 %}{% assign type_count = type_count | plus: 1 %}{% endif %}

{% assign search_category = blank %}
{% assign search_filter_string = blank %}
{%- if search.performed -%}
{% assign field_prefixes = ‘product_type: tag:’ | split: ’ ’ %}
{% for field_prefix in field_prefixes %}
{% if search.terms contains field_prefix %}
{% assign search_filter = search.terms | split: field_prefix | last %}
{% assign search_category = search_filter | remove: ‘searchfilter_’ %}
{% assign search_filter_string = field_prefix | append: search_filter %}
{% break %}
{% endif %}
{% endfor %}
{%- endif -%}

{%
render ‘breadcrumbs’,
search_category: search_category,
%}

{{ page_title }}

{% render 'page-search-form', enable_content: enable_content, search_filter_string: search_filter_string, sanitized_terms: sanitized_terms, %}

{% if product_count > 0 %}

{{ 'general.accessibility.search_products' | t }}

    {% for item in search.results %} {% if item.object_type != 'product' %}{% continue %}{% endif %} {% render 'product-grid-item', product: item %} {% endfor %}
{% else %}
{% assign title = 'search.general.no_search_performed' | t %}

{% if search.performed %}
{% capture sanitized_terms %}
{%
render ‘search-sanitizer’,
search_terms: search.terms
%}
{% endcapture %}

{% assign sanitized_terms = sanitized_terms | strip %}

{%- if search_category != blank -%}
{%
assign title = ‘search.general.no_results_products_title_in_category’
| t: terms: sanitized_terms, category: search_category
%}
{%- else -%}
{% assign title = ‘search.general.no_results_products_title’ | t: terms: sanitized_terms %}
{%- endif -%}

{% if paginate.current_page > 1 %}
{%- if search_category != blank -%}
{%
assign title = ‘search.general.no_more_results_products_title_in_category’
| t: terms: sanitized_terms, category: search_category
%}
{%- else -%}
{% assign title = ‘search.general.no_more_results_products_title’ | t: terms: sanitized_terms %}
{%- endif -%}
{% endif %}
{% endif %}

{{ title }}

{% if search.performed %}

{{ ‘search.general.view_all_products’ | t }}

{% endif %}

{% endif %}

{% if enable_content and search.performed and search_category == blank %}

{% render 'results-search-content', title: 'search.general.posts_title', results: search.results, results_type: 'article', results_count: article_count %}

{%
render ‘results-search-content’,
title: ‘search.general.pages_title’,
results: search.results,
results_type: ‘page’,
results_count: page_count
%}

{% endif %}

{% render ‘pagination’, paginate: paginate %}

{% render 'quick-shop' %} {% endpaginate %}

{% schema %}
{
“name”: “Search results”,
“class”: “search–section section–canonical”,
“settings”: [
{
“type”: “range”,
“id”: “results_per_page_range”,
“label”: “Results per page”,
“min”: 24,
“max”: 48,
“step”: 12,
“default”: 24
},
{
“type”: “select”,
“id”: “products_per_row”,
“label”: “Products per row”,
“options”: [
{
“label”: “3”,
“value”: “3”
},
{
“label”: “4”,
“value”: “4”
}
],
“default”: “4”
},
{
“id”: “enable_search_articles_pages”,
“type”: “checkbox”,
“label”: “Show blog posts and pages in search results”,
“default”: true
}
]
}

{% endschema %}

I’m not sure which file to edit and also, where to add the script

@Denise_Glezer-J it seems your version does have the search.terms variable so you should be able to place the code just above the {% schema %} tag or at the end of the file you posted. I’m unable to test as I’m running dawn version.

Let me know how it goes.

Do you mean this script:

@Denise_Glezer-J yes insert that code into the file you posted and refresh the page, then try to search one of those terms (“Carbsmart”, “carb smart”, “Carb Smart”). If it does not work then just remove the code and resave the file.

OK I tried posting in both places, and sadly neither worked

@Denise_Glezer-J hmmm try below. I replaced search.terms with sanitized_terms.

I will try to look into other options if that does not work.

@Denise_Glezer-J also please try the following. Search using your header search bar. Then use the search bar that appears on that second page after it loads the results. I think you may have different files for each search bar.

Also, try both versions of the scripts I gave you one at a time with both the search.term and sanitized_terms set for the searchVal variable.

@Denise_Glezer-J This search bar:

YIPPEEEEE it’s working!

I added:

to the end of static-search.liquid file and I searched using the first search bar in the header. After I pressed enter, it directed me to my carbsmart collection.

Thank you so, so much!!!

@Denise_Glezer-J No problem! Glad I could help.