You are here:  » Converting "Order by relevance|price" links to dropdown.


Converting "Order by relevance|price" links to dropdown.

Submitted by znewman on Sun, 2008-02-17 22:52 in

Hi,

I've been struggling to convert the "order by: relevance|price" links that get displayed in the banner on the search page to a simple drop down list of the options instead. It seems like it should be an easy thing to do, but I have managed to achieve all sorts of undesirable effects! Can anyone help me?

Thanks
Zoe

Submitted by support on Mon, 2008-02-18 08:41

Hello Zoe,

The sort links are generated by this code in search.php (line 147 in the distribution):

$banner["h3"] = translate("Order by").": ".$sortRelevance.$sortRating." | ".translate("Price").": ".$sortPriceAsc.", ".$sortPriceDesc;

To replace the direct links with a form, replace this with:

      $sortForm = "";
      $sortForm .= "Order by: ";
      $sortForm .= "<form method='GET' 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' />";
      if ($minPrice) $sortForm .= "<input type='hidden' name='minPrice' value='".htmlentities($minPrice,ENT_QUOTES,$config_charset)."' />";
      if ($maxPrice) $sortForm .= "<input type='hidden' name='maxPrice' value='".htmlentities($maxPrice,ENT_QUOTES,$config_charset)."' />";
      if ($merchantFilter) $sortForm .= "<input type='hidden' name='merchantFilter' value='".htmlentities($merchantFilter,ENT_QUOTES,$config_charset)."' />";
      if ($categoryFilter) $sortForm .= "<input type='hidden' name='categoryFilter' value='".htmlentities($categoryFilter,ENT_QUOTES,$config_charset)."' />";
      if ($brandFilter) $sortForm .= "<input type='hidden' name='brandFilter' value='".htmlentities($brandFilter,ENT_QUOTES,$config_charset)."' />";
      $sortForm .= "<select name='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 - Ascending</option>";
      $sortForm .= "<option value='priceDesc' ".($sort=="priceDesc"?"selected='selected'":"").">Price - Descending</option>";
      $sortForm .= "</select>";
      $sortForm .= "<noscript><input type='submit' value='Go' /></noscript>";
      $sortForm .= "</form>";
      $banner["h3"] = $sortForm;

I've made it so that the currently selected sort order is selected by default in the drop down box. Note the use of style='display:inline;' to keep the form on the same level as the "Order by: " text.

Cheers!
David.

Submitted by don_load on Mon, 2010-02-01 08:43

Hi David,

Was going through the various mods posted and came across this one. The drop-down wasn't reloading the page for me so after some googling I found that replacing
JavaScript:this.submit(); with JavaScript:this.form.submit(); seemed to do the trick and its now working ok. I know this is almost 2 years old now but thought it might help out anyone that can't get it working.

Submitted by support on Mon, 2010-02-01 10:12

Thanks, Jay!

Cheers,
David.

Submitted by rassad on Tue, 2010-09-28 15:59

Hi, I used the above code but was unable to get this working,

I got an error on my site at {link saved}

any ideas?

thanks

Submitted by support on Wed, 2010-09-29 09:09

Hi,

In your form, I notice that there is a : missing from the onChange attribute of the select box, make sure it is this:

onchange='JavaScript:this.form.submit();'

Also, I notice that your setting for $config_currencyHTML in config.php is not quite correct for the pound sign - it should be:

  $config_currencyHTML = "&pound;";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by rassad on Wed, 2010-09-29 09:45

Hi David,

Thanks for spotting the &pound code, i didnt see that, I have edited the javascript but am still getting an "expected ;" error.

Thanks

Submitted by support on Wed, 2010-09-29 09:56

Hi,

I think that's referring to the style attribute of the tag, there is a missing : at the moment, make sure it is:

style='display:inline;'

Cheers,
David.
--
PriceTapestry.com

Submitted by rassad on Wed, 2010-09-29 10:04

Hi David,

here is my code for the dropdown, thanks

      $sortForm = "";
      $sortForm .= "Order by: ";
      $sortForm .= "<form method='GET' 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' 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 - Ascending</option>";
      $sortForm .= "<option value='priceDesc' ".($sort=="priceDesc"?"selected='selected'":"").">Price - Descending</option>";
      $sortForm .= "</select>";
      $sortForm .= "<noscript><input type='submit' value='Go' /></noscript>";
      $sortForm .= "</form>";
      $banner["h3"] = $sortForm;

Submitted by support on Wed, 2010-09-29 10:36

Hi,

In your output, the following is being generated...

<input type='hidden' name='q' value='A1Gifts <input type='hidden' name='page' value='1' />

...however the code above looks fine, and I also checked it in the search.php that you have sent me regarding the filter query; so I'll add the filter code and then if the drop-down form is still not working I'll check that out also...

Cheers,
David.
--
PriceTapestry.com

Submitted by rassad on Thu, 2010-09-30 09:01

Hi David,

Thanks for the files, but after uploading the search returns a blank page.

Thanks

Submitted by support on Thu, 2010-09-30 09:20

Hi,

There was a mistake in one of the files I sent you which I have found and just re-sent for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by rassad on Thu, 2010-09-30 09:27

Hi,

thanks for the files..but i am not seeing any filters after running a search at rassad.co.uk

thanks

Submitted by support on Thu, 2010-09-30 09:40

Hi,

It may be that the PHP $_SERVER variables are not populated on your installation. In html/user_header_after.php look for the following code at line 8:

if (strpos($_SERVER["PHP_SELF"],"search.php") && $numResults)

...and REPLACE that with just:

if ($numResults)

Cheers,
David.
--
PriceTapestry.com

Submitted by rassad on Fri, 2010-10-01 07:38

Hi David,

I replaced the code but I dont think its working.

Thanks

Submitted by support on Fri, 2010-10-01 08:40

Hi,

I don't see the filter HTML code within the left hand sidebar, and there also seems to be both left and right sidebar code in your right hand sidebar region...

Please could you email me your html/user_header_after.php and html/user_footer_before.php and I'll check them both out plus I'll add / check the sidebar code...

Cheers,
David.
--
PriceTapestry.com

Submitted by rassad on Fri, 2010-10-01 09:16

Hi David,

Will send now.

Thanks for all your support!