You are here:  » Sidebar Filters and Drop down Sort

Support Forum



Sidebar Filters and Drop down Sort

Submitted by chrisst1 on Mon, 2011-08-01 15:46 in

Hi David

I'm using the following form http://www.pricetapestry.com/node/1884
in your modified sidebar filters search.php to sort results which works fine on a normal search but will not sort filted results.

      $sortForm = "";
      $sortForm .= "Sort by ";
      $sortForm .= "<form method='GET' id='sortform' style='display:inline;' action='".$config_baseHREF."search.php'>";
      $sortForm .= "<input type='hidden' name='q' value='".htmlentities($q,ENT_QUOTES,$config_charset)."' />";
      $sortForm .= "<input type='hidden' name='page' value='1' />";
      $sortForm .= "<select name='sort' id='sort' onchange='JavaScript:this.form.submit();'>";
      $sortForm .= "<option value='relevance' ".($sort=="relevance"?"selected='selected'":"")." >Relevance</option>";
      $sortForm .= "<option value='rating' ".($sort=="rating"?"selected='selected'":"")." >Product Rating</option>";
      $sortForm .= "<option value='priceAsc' ".($sort=="priceAsc"?"selected='selected'":"")." >Price - Low</option>";
      $sortForm .= "<option value='priceDesc' ".($sort=="priceDesc"?"selected='selected'":"").">Price - High</option>";
      $sortForm .= "<option value='nameAZ' ".($sort=="nameAZ"?"selected='selected'":"")." >Product A-Z</option>";
      $sortForm .= "<option value='nameZA' ".($sort=="nameZA"?"selected='selected'":"")." >Product Z-A</option>";
      $sortForm .= "</select>";
      $sortForm .= "<noscript><input type='submit' value='Go' /></noscript>";
      $sortForm .= "</form>";
      $banner["sort"] = $sortForm;

I suspect that the form is ignoring the code starting on line 406 as the normal h3 text sort without the sort form works fine.

if ($merchantFilter)
{
$sort .= "&merchantFilter=".urlencode($merchantFilter);
}
if ($categoryFilter)
{
$sort .= "&categoryFilter=".urlencode($categoryFilter);
}
if ($brandFilter)
{
$sort .= "&brandFilter=".urlencode($brandFilter);
}

Any ideas

Chris

Submitted by support on Mon, 2011-08-01 16:05

Hi Chris,

You're absolutely correct - the filter variables need to be passed through as hidden fields in the form. In your sort form drop-down code, where you have:

      $sortForm .= "<input type='hidden' name='page' value='1' />";

REPLACE with:

      $sortForm .= "<input type='hidden' name='page' value='1' />";
      $sortForm .= "<input type='hidden' name='merchantFilter' value='".htmlentities($merchantFilter,ENT_QUOTES,$config_charset)."' />";
      $sortForm .= "<input type='hidden' name='categoryFilter' value='".htmlentities($categoryFilter,ENT_QUOTES,$config_charset)."' />";
      $sortForm .= "<input type='hidden' name='brandFilter' value='".htmlentities($brandFilter,ENT_QUOTES,$config_charset)."' />";

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Tue, 2011-08-02 14:14

Hi David

Tried the above, still not working for some reason.

// START CUSTOM
      $sortForm = "";
      $sortForm .= "Sort by ";
      $sortForm .= "<form method='GET' id='sortform' style='display:inline;' action='".$config_baseHREF."search.php'>";
      $sortForm .= "<input type='hidden' name='q' value='".htmlentities($q,ENT_QUOTES,$config_charset)."' />";
      $sortForm .= "<input type='hidden' name='page' value='1' />";
      $sortForm .= "<input type='hidden' name='merchantFilter' value='".htmlentities($merchantFilter,ENT_QUOTES,$config_charset)."' />";
      $sortForm .= "<input type='hidden' name='categoryFilter' value='".htmlentities($categoryFilter,ENT_QUOTES,$config_charset)."' />";
      $sortForm .= "<input type='hidden' name='brandFilter' value='".htmlentities($brandFilter,ENT_QUOTES,$config_charset)."' />";
      $sortForm .= "<select name='sort' id='sort' onchange='JavaScript:this.form.submit();'>";
      $sortForm .= "<option value='relevance' ".($sort=="relevance"?"selected='selected'":"")." >Relevance</option>";
      $sortForm .= "<option value='rating' ".($sort=="rating"?"selected='selected'":"")." >Product Rating</option>";
      $sortForm .= "<option value='priceAsc' ".($sort=="priceAsc"?"selected='selected'":"")." >Price - Low</option>";
      $sortForm .= "<option value='priceDesc' ".($sort=="priceDesc"?"selected='selected'":"").">Price - High</option>";
      $sortForm .= "<option value='nameAZ' ".($sort=="nameAZ"?"selected='selected'":"")." >Product A-Z</option>";
      $sortForm .= "<option value='nameZA' ".($sort=="nameZA"?"selected='selected'":"")." >Product Z-A</option>";
      $sortForm .= "</select>";
      $sortForm .= "<noscript><input type='submit' value='Go' /></noscript>";
      $sortForm .= "</form>";
      $banner["sort"] = $sortForm;
// END CUSTOM

Chris

Submitted by support on Tue, 2011-08-02 14:24

Hi Chris,

Could you post a link to a search results page where the drop-down isn't working and I'll take a look (I'll remove the link before publishing your reply)...

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Tue, 2011-08-02 14:49

Link:

{link saved}

Submitted by support on Tue, 2011-08-02 14:56

Thanks Chris,

I applied a Merchant Filter (from the sidebar filters), and then re-sorted and the form correctly re-submitted the merchant filter. I also did a view > source to verify that the hidden fields were included correctly and they all look fine; if you're still not sure could you post a link to a page that doesn't appear to be working correctly after changing the sort and I'll check it out further...

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Tue, 2011-08-02 15:12

Hi David

What we are finding is that when a filter is applied to the above (link) 142 search results

{link saved}

that works fine and shows 47 results, however when trying to sort those 47 products using the sort form it returns the original 142 products.

Does that help?

Chris

Submitted by support on Tue, 2011-08-02 15:22

Thanks Chris, I can see the problem.

minPrice and maxPrice are not being propagated through the sort order drop-down form; so at the same point in the code where you added the merchant/category/brand filter hidden fields, further add:

      $sortForm .= "<input type='hidden' name='minPrice' value='".$minPrice."' />";
      $sortForm .= "<input type='hidden' name='maxPrice' value='".$maxPrice."' />";

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Tue, 2011-08-02 15:38

David

Brilliant! That's fixed it.

Thank you David

I've got another for you (i've look through loads of PT forum pages but can't it)

How would I go about showing based upon the search query the top 10 categories, brands and merchants containing that search term with click through to those results.

I.e
Categories
Red (15)
Red color (10)

Merchants
Pet store1 (22)
Pet store2 (19)

Chris

Submitted by support on Wed, 2011-08-03 08:32

Hi Chris,

Could you email me your file that contains your current filters, and I'll add the code from the list version of the filters to do this for you (limited to top 10 results)...

Cheers,
David.
--
PriceTapestry.com

Submitted by chrisst1 on Thu, 2011-08-04 16:34

Hi David

That worked great, thanks for doing that, very much appreciated.

Chris

Submitted by quokka on Wed, 2011-09-21 07:03

Hi David,

Installed this mod, but the product AZ and product ZA sort doesn't work..
I don't see the code to order by in my search.php

Any help would be highly appreciated..

Here's my search.php code:

{code saved}

Submitted by support on Wed, 2011-09-21 08:54

Hi bas,

The nameAZ and nameZA order by entries were missing from the $orderByDefault and $orderByFullText arrays - in your code, replace this section:

    $orderByDefault = array();
    $orderByDefault["rating"] = "rating DESC";
    $orderByDefault["priceAsc"] = "minPrice ASC";
    $orderByDefault["priceDesc"] = "minPrice DESC";
    $orderByFullText = array();
    $orderByFullText["relevance"] = "relevance DESC";
    $orderByFullText["rating"] = "rating DESC";
    $orderByFullText["priceAsc"] = "minPrice ASC";
    $orderByFullText["priceDesc"] = "minPrice DESC";

...with:

    $orderByDefault = array();
    $orderByDefault["rating"] = "rating DESC";
    $orderByDefault["priceAsc"] = "minPrice ASC";
    $orderByDefault["priceDesc"] = "minPrice DESC";
    $orderByDefault["nameAZ"] = "name ASC";
    $orderByDefault["nameZA"] = "name DESC";
    $orderByFullText = array();
    $orderByFullText["relevance"] = "relevance DESC";
    $orderByFullText["rating"] = "rating DESC";
    $orderByFullText["priceAsc"] = "minPrice ASC";
    $orderByFullText["priceDesc"] = "minPrice DESC";
    $orderByFullText["nameAZ"] = "name ASC";
    $orderByFullText["nameZA"] = "name DESC";

That should be all it is!

Cheers,
David.
--
PriceTapestry.com

Submitted by quokka on Thu, 2011-09-22 19:29

Hmm, should have been able to fixe that myself ;)

Thanks once again David!