Jump to content

[Resolved] Way to add Search Suggestions if NONE Found?


Dirty Butter

Recommended Posts

I have code from Bsmither that shows the terms people used in a search.searchnonefound.png

 

It would be great if I could use that blank space where nothing is shown, to offer suggestions - such as

Didn't find anything?

Please double check your spelling.

Search again without "little words" such as the, with, and ...

When we describe lovies we use small, large, xl if we are talking about the size. So you are not going to find it if you use huge or giant or big.

**************

Any suggestions how to accomplish that?

Link to comment
Share on other sites

If it's the case where nothing was found (as opposed to a search not returning false but having an empty array of products - it could happen), we can have CubeCart do a bounce to a document.

The document need not be visible, and it would contain a link back to Advanced Search.

 

Link to comment
Share on other sites

Just to cap off the previous approach: the skin template content.404.php can be externally edited to have whatever is desired.

Having a separate SiteDoc allows for that SiteDoc to be in the list of other SiteDocs if desired.

Shortly, I will have code to fetch the document on 404 scenarios.

Link to comment
Share on other sites

404? My mistake. Getting confused with another thread.

Step One: Create a document and enable it. Compose whatever you want to say about what to do when searches come back empty. This document will appear in the SiteDocs box, so suggest to make it relevant from a stand-alone perspective, not just only when searches come up empty. Make note of the document's "Custom SEO URL Path". It will be used in the snippet below.

Step Two: Make a code snippet.

Enabled: checked
Unique ID: empty_search_results@cc6
Execution Order: 99
Description: 302 Bounce (to specific SiteDoc or other page)
Trigger: class.cubecart.pre_display_category
PHP Code:
<?php
if (isset($_REQUEST['search']['keywords']) && empty($products)) { // search keywords used but no products found
httpredir('custom_seo_url_path.html');
}

There are other ways to get basically the same end result:

?_a=template: This will find a file named inline.php in a modules folder and make it the PAGE_CONTENT of the main template. This file is not actually a template. It is a finalized chunk of HTML that will show up in the main area of the web page.

?_a=plugin: This fetches a specific hook in a plugin. The plugin need not be 100% complete.

Both have their pluses and minuses. I think the 302 Bounce to a SiteDoc gives us the most versatility, especially when the SiteDoc contents can be parsed through Smarty if desired.

Link to comment
Share on other sites

I've created my document and the snippet. But when I use a term that will not be found - it goes to the document correctly - but it does NOT make it clear that they arrived there because their search did not work.

It would be great if it kept the

Products found matching 'annniversary' were not found. Is there any way to get that 'annniversary' part into the document?

IF I hide the document, I can easily change the wording to make it obvious. Should I just make TWO documents - one visible and one hidden with appropriate wording changes?

Link to comment
Share on other sites

"it does NOT make it clear that they arrived there because their search did not work"

More should be added to the document making that explanation.

However, I said to have content that should stand on it's own, and it sounds like that is what you have done.

We can have CubeCart send the document through the Smarty Parser.

1. We will need to know what data is available at the time the document is parsed.
2. We also have globally available variables at our disposal.

"IF I hide the document..."

I do not know where you are going with this.

Ok, let's make a few changes:

Open the document for editing. Enable the Smarty parser. At the end of the document content, add {debug}.

At the top of the document content, add:

{if $smarty.get.search.keywords}Searched: {$smarty.get.search.keywords|escape}{/if}

In the code snippet, change:

From:

<?php
if (isset($_REQUEST['search']['keywords']) && empty($products)) { // search keywords used but no products found
httpredir('custom_seo_url_path.html');
}

To:

<?php
if (isset($_REQUEST['search']['keywords']) && empty($products)) { // search keywords used but no products found
httpredir('custom_seo_url_path.html?search[keywords]='.urlencode($_REQUEST['search']['keywords']));
}

 

Link to comment
Share on other sites

Done. What should I look for in the debug window? The incorrect search term does show in the Not Found document - i just need to move where it is in the document, if that's possible.

I made TWO Search Tip documents - one seen and one hidden that is worded appropriately to fit an unsuccessful search.

Link to comment
Share on other sites

The debug window shows you what is available to add into the document. All the language phrases, some store configuration settings, but not much else.

Also, Smarty gives us certain global variables. You can see what is available in a few of these variables by looking at CubeCart's debug grey section at the bottom of the page. Smarty has access to: $_GET, $_POST, $_REQUEST, $_SESSION, $_COOKIE, $_SERVER, and a few more.

Link to comment
Share on other sites

  • 1 year later...

I've copied the snippet code over to a test 6.2.1 site and created the corresponding document. The document is enabled but not showing on the storefront. I can input the url on the storefront and it shows properly.

But when I intentionally search for a junk word, it goes to the 404 page, not the document. This happens on the stock install as well.

Something must be different in 6.2.1, but I don't have an idea what it is.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...