You are here:  » Sort by issue - keep other selection


Sort by issue - keep other selection

Submitted by tisbris on Wed, 2013-05-15 17:52 in

Hello David

I'm almost done making a 100% responsive theme for PT.
I'm strugling with the sort by function.

I got a dropdown for relevance, rating... and a dropdown for number of results 10, 20....
The problem is that these dropdown is resetting each other.

I really like to have these dropdowns to keep al other select values include already selection in searchfilter.

And last - how do I get a userfriendly name in the sort by dropdown?

this is my search.php:
{code saved}

//Brian

Submitted by support on Thu, 2013-05-16 08:56

Hello Brian,

Each of your drop down forms should ideally have all other search variables included as hidden fields. I see that your "show" drop-down already has sort as a hidden field, so where you have this code at line 304:

  $showForm .= "<input type='hidden' name='sort' value='".htmlentities($sort)."' />";

...REPLACE that with:

  $showForm .= "<input type='hidden' name='sort' value='".htmlentities($sort)."' />";
  if ($minPrice) $showForm .= "<input type='hidden' name='minPrice' value='".htmlentities($minPrice)."' />";
  if ($maxPrice) $showForm .= "<input type='hidden' name='maxPrice' value='".htmlentities($maxPrice)."' />";
  if ($merchantFilter) $showForm .= "<input type='hidden' name='merchantFilter' value='".htmlentities($merchantFilter)."' />";
  if ($categoryFilter) $showForm .= "<input type='hidden' name='categoryFilter' value='".htmlentities($categoryFilter)."' />";
  if ($brandFilter) $showForm .= "<input type='hidden' name='brandFilter' value='".htmlentities($brandFilter)."' />";

Similarly, for your sort drop-down, where you have the following code at line 353:

  $sortForm .= "<input type='hidden' name='q' value='".htmlentities($q)."' />";

...REPLACE with:

  $sortForm .= "<input type='hidden' name='q' value='".htmlentities($q)."' />";
  if ($minPrice) $sortForm .= "<input type='hidden' name='minPrice' value='".htmlentities($minPrice)."' />";
  if ($maxPrice) $sortForm .= "<input type='hidden' name='maxPrice' value='".htmlentities($maxPrice)."' />";
  if ($merchantFilter) $sortForm .= "<input type='hidden' name='merchantFilter' value='".htmlentities($merchantFilter)."' />";
  if ($categoryFilter) $sortForm .= "<input type='hidden' name='categoryFilter' value='".htmlentities($categoryFilter)."' />";
  if ($brandFilter) $sortForm .= "<input type='hidden' name='brandFilter' value='".htmlentities($brandFilter)."'

For friendly names in the sort drop-down, it looks like a version of the $sortOptions array was already in place but commented out, so if you restore (but I assume you no longer want rating) this as follows:

      $sortOptions = array(
        "relevance" => translate("Relevance"),
        "priceAsc" => translate("Price: Low to High"),
        "priceDesc" => translate("Price: High to Low"));

And then as your foreach loop, use:

      foreach($sortOptions as $w => $display)
      {
        $selected = (($sort == $w)?"selected='selected'":"");
        $sortForm .= "<option value='".$w."' ".$selected.">".$display."</option>";
      }

Cheers,
David.
--
PriceTapestry.com