Page 1 of 1
Default sort-order, direction
Posted: Thu Feb 09, 2023 12:42 pm
by Kofod95
I think I've hit a wall on this one.
I would like listing to default to newest products first and I've tried this hook (and a few variations) without luck:
Code: Select all
class hook_shop_filter_zdefaultSort {
public function listen_filterStart($parameters) {
if ('PRODUCT_LIST_NAME' === $parameters['default_column']) {
$parameters['default_column'] = 'PRODUCT_LIST_ID';
$parameters['direction'] = 'DESC';
}
}
}
It does change the default column, but I fail regarding the direction.
Does
this mean I should use a "later" listener, or am I just doing it very wrong?
//Daniel
Re: Default sort-order, direction
Posted: Thu Feb 09, 2023 2:45 pm
by Omar_one
@Kofod95 on the old forum @Denzel shared a hook for default sorting order
Re: Default sort-order, direction
Posted: Thu Feb 09, 2023 3:44 pm
by Kofod95
If I remember correctly, that one wrote a new $_GET['sort'] which works and I may do that, I'm just curious with this one
//Daniel
Re: Default sort-order, direction
Posted: Thu Feb 09, 2023 10:57 pm
by ecartz
Kofod95 wrote: ↑Thu Feb 09, 2023 12:42 pm
Does
this mean I should use a "later" listener
Yes, a later listener, but I don't know that it exists. For now, the $_GET['sort'] method is probably the most practical way to get it done.
Re: Default sort-order, direction
Posted: Sat Feb 11, 2023 12:55 pm
by Denzel
Code: Select all
<?php
/*
Copyright (c) 2020, Denzel
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Set the default sort order corresponding your setting in configuration -> productlisting:
for example '1a' = name asc. '1b' = name desc. '2a' = price asc. '2d' = price desc. and so on.
*/
class hook_shop_siteWide_defaultSortOrder {
function listen_injectRedirects() {
if (!isset($_GET['sort'])) {
$_GET['sort'] = '2d'; // <--- change sort order here !
}
}
}
This works for my 1.0.8.18 Installation.