Sort search results by select attribute
Permalink Browser Info Environment
I've added a select Attribute to my real estate listings and the client wants the search results to initially sort by quality: Signature, Executive, Premium, Quality. This is not the case for search results. They are being sorted alphabetically instead. How can I change the search results to sort by the Attribute search rankings?
Type: | Discussion |
---|---|
Status: | New |
There should be a few options for sorting, but the default package doesn't offer the ability to sort by attribute like quantity, so this is something you'd have to add yourself. Take a look within the real estate search block's controller within the package to see how the other sorting is done. I'll try to look at the code this weekend for you too to see if I can get you a more specific code snippet to put in there.
Hi Tony,
Have you had a chance to look into the support issue?
Have you had a chance to look into the support issue?
there's this commented out section within /packages/tony_real_estate/blocks/tony_real_estate_search/controller.php:
uncommenting that snippet will enable sorting by custom attributes. Notice that the id needs to be in the format of fak_123, where 123 is the attribute key id.
You'll also want to add that option up above where the available sorting options are defined:
uncommenting that snippet will enable sorting by custom attributes. Notice that the id needs to be in the format of fak_123, where 123 is the attribute key id.
You'll also want to add that option up above where the available sorting options are defined:
public function getDefaultSortableOpts(){ $details=array(); //$details['title'] = t('Title'); $details['newest'] = t('Newest'); $details['oldest'] = t('Oldest'); $details['price'] = t('Price: Low to High'); $details['price_desc'] = t('Price: High to Low'); $details['alpha_asc'] = t('Alphabetical'); //(must use page name as title) $details['display_order'] = t('Display Order'); //(sorted within sitemap) $details['fak_123'] = t('My Attribute Name'); return $details; }
I tried changing my code but nothing changed.
Here is what I changed it to:
Am I missing something or did I do something wrong?
I also noticed that now if I change the Sort By option I get different results for the order of Quality properties. They are still not in order of Quality. Here is an example:http://www.bbranch.vemglobal.net/lodging/vacation-rental-search/vac...
Here is what I changed it to:
elseif( substr($sortBy,0,4)=='fak_' ){ $fak_69=substr($sortBy,4); $ak = CollectionAttributeKey::get( intval($fak_69) ); if(is_object($ak)) $pagelist->sortByAttributeKey( $ak, $sortAscDesc); }elseif($sortBy=='oldest'){ $pagelist->sortBy('cDateAdded', 'asc'); }elseif($sortBy=='fak_69'){ $ak = CollectionAttributeKey::getByHandle( 'fak_69' ); if(is_object($ak)) $pagelist->sortBy( $ak, 'desc'); } elseif($sortBy=='sleeps'){ $ak = CollectionAttributeKey::getByHandle( 'sleeps' ); if(is_object($ak)) $pagelist->sortBy( $ak, 'desc'); } elseif($sortBy=='bedrooms'){ $ak = CollectionAttributeKey::getByHandle( 'bedrooms' ); if(is_object($ak)) $pagelist->sortBy( $ak, 'desc'); }
Viewing 15 lines of 29 lines. View entire code block.
Am I missing something or did I do something wrong?
I also noticed that now if I change the Sort By option I get different results for the order of Quality properties. They are still not in order of Quality. Here is an example:http://www.bbranch.vemglobal.net/lodging/vacation-rental-search/vac...
Can you tell if it's getting of those elseif condition sections? You could test it by adding some echo $sortBy; and die; statements to each section.