Jump to content

Need Help with SORT with Search


Dirty Butter

Recommended Posts

My Sort works with listings in a Category. But it does not work in either the Search box or Advanced Search results page. Changing the default in Admin effects Category as it should, but has no effect on Search results.

What files should I check to debug this? My Search is NOT stock, but rather code provided by @bsmither. As far as I know nothing to do with sort has been edited, however.

Link to comment
Share on other sites

Please experiment with this small edit:

In the skin template box.search.php, find near line 22 (for Foundation):

<input type="hidden" name="_a" value="category">

On a new blank line after that, add:

<input type="hidden" name="sort[{$CONFIG.product_sort_column}]" value="{$CONFIG.product_sort_direction}">

This adds a sort parameter to the querystring that is according to the Store Settings. The Quick Search box uses the GET method when submitting that form.

When showing a list of results, the sorter is suppose to show how the list is sorted - if the sorted method is one of up to five defined methods. (Store Settings is potentially unlimited.)

If the method shown is not one of the defined methods, the sorter is supposed to show "--Please Select--", but it doesn't. That's because the "--Please Select--" option is listed as the first option (that's good), it is disabled and can't be selected (that's good), and all other options do not have the 'selected' attribute (that's to be expected). But with these conditions, browsers will generally show as default the first 'viable' choice (not good).

So, to indicate that the results list is not sorted by the (implied) indicated method, we need to force the browser to show "--Please Select--".

In the skin template content.category.php, find near line 45 (for Foundation):

<select name="sort" id="product_sort">
  <option value="" disabled>{$LANG.form.please_select}</option>

Change to:

<select name="sort" id="product_sort">
  <option value="" disabled selected>{$LANG.form.please_select}</option>

You may ask, then what happens when one of the defined sort methods gets the 'selected' attribute? That means two options have the 'selected' attribute. Technically, this is illegal (HTML may not 'validate').

True, although I have not tried this with every known browser, at least Firefox will show the last option with the 'selected' attribute in the drop-down selector.

I figured a way around that, if anyone needs their HTML to validate.

Link to comment
Share on other sites

I get a page refresh when I change the Sort, but the list order does not change - that happens no matter which sort method I choose. Your edits did not help my situation.

Here's the url after the page refreshes:

https://dirtybutter.com/plushcatalog/search.html?_a=category&search[keywords]=CARTERS%20BLUE%20DOG&sort[date_added]=ASC

 

Link to comment
Share on other sites

I've been known to hijack a few threads myself lol. np

The CC demo store creates the same url I get, but their sort works. I tried to enable debugging in the Demo admin, but it's evidently not allowed, as I get a blank page. So I created another demo store TV product so I would have something to sort on the demo store. Then I watched the waterfall. I just barely understand how to use the waterfall, but I couldn't see anything obviously different in my waterfall results on my store Sort and on the Demo store sort.

MY Search (that you created) uses the meta_keywords instead of the description. Would that be the reason mine doesn't work?

Link to comment
Share on other sites

The waterfall will not reveal how CubeCart processes (or ignores, or overrules) the sort parameters given to it.

To find out why YOUR searchCatalogue() function is not sorting on search results as one would expect, we would need to peek at the function's execution.

Send me an email with a copy of your catalogue.class.php file.

 

Link to comment
Share on other sites

'Sort by' wasn't working properly, but that was fixed (see here).

Note also that search results are always sorted by relevance on the first page load - the admin product listing order setting is used when browsing the store categories, not for search results.

You can change that behavior by removing the following lines from your `searchCatalogue` method:

// starting on line 1618 using the most recent CubeCart code from GitHub:
} elseif ($search_mode == 'fulltext') {
	$order['field'] = 'Relevance';
	$order['sort'] = 'DESC';
} // leave this closing brace

That will then default to the store setting for sorting search results.

Of course, if you have a substantially modified version of that file, you will have to wait for bhsmither's assistance.

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...