You are here:  » Order by Size

Support Forum



Order by Size

Submitted by paddyman on Mon, 2007-01-22 21:59 in

Hi David,

I have a field called size in my feed which gives the size of Hard Drives. So values can be 80GB, 120GB....... and so on.

Would like to have an option in search results to order by Size. Don't have any problem in getting the size field into PT to register it, just don't know where and how to create the query.

Hope you can help :)

Thanks

Paddyman

Submitted by support on Tue, 2007-01-23 05:59

Hi,

The sort field is selected in search.php in the following block of code (starting at line 14 in the distribution):

    $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";

Assuming that your size field is called "size", the first step is to add two lines to the above code to add the size option:

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

Secondly, you need to add the links to sort the results by size (ascending and descending). Find the following code (starting at line 122):

      $sortPriceDesc = ($sort=="priceDesc"?"<strong>".translate("High to Low")."</strong>":"<a href='".$sortHREF."priceDesc'>".translate("High to Low")."</a>");
      $banner["h3"] = translate("Order by").": ".$sortRelevance.$sortRating." | ".translate("Price").": ".$sortPriceAsc.", ".$sortPriceDesc;

..and change this as follows:

      $sortPriceDesc = ($sort=="priceDesc"?"<strong>".translate("High to Low")."</strong>":"<a href='".$sortHREF."priceDesc'>".translate("High to Low")."</a>");
      $sortSizeAsc = ($sort=="size"?"<strong>HDD Size (Low to High)</strong>":"<a href='".$sortHREF."sizeAsc'>HDD Size (Low to High)</a>");
      $sortSizeDesc = ($sort=="size"?"<strong>HDD Size (High to Low)</strong>":"<a href='".$sortHREF."sizeDesc'>HDD Size (High to Low)</a>");
      $banner["h3"] = translate("Order by").": ".$sortRelevance.$sortRating." | ".translate("Price").": ".$sortPriceAsc.", ".$sortPriceDesc." | Features: ".$sortSizeAsc.", ".$sortSizeDesc;

If you don't want to offer ascending and descending, simply modify that list line to only show the option you want to display...

Hope this helps,
Cheers,
David.