Here I go sticking my neck out again...
Regarding the product listing default sort order code in
/includes/index_filters/default_filter.php…
1) Question
PHP Code:
if (isset($_GET['sort']) && strlen($_GET['sort']) > 3) {
$_GET['sort'] = substr($_GET['sort'], 0, 3);
}
Why is this limited to three when as far as I can see, the code deals only with two characters eg 2a?
2) Bug (?)
On initial page load $_GET['sort'] is not set.
If there is a sort order defined in the admin, this gets put into $_GET['sort']:
PHP Code:
if (!isset($_GET['sort']) and PRODUCT_LISTING_DEFAULT_SORT_ORDER != '') {
$_GET['sort'] = PRODUCT_LISTING_DEFAULT_SORT_ORDER;
}
If
there is no default sort order defined in the admin
OR $_GET['sort'] contains characters not 1-8 or a or d ( Question: Why are column numbers 1-8 allowed when there are only 7 options?)
OR the number character is more than the number of display-enabled columns:
then this loop runs:
PHP Code:
for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
if (isset($column_list[$i]) && $column_list[$i] == 'PRODUCT_LIST_NAME') {
$_GET['sort'] = $i+1 . 'a';
$listing_sql .= " order by p.products_sort_order, pd.products_name";
break;
} else {
// sort by products_sort_order when PRODUCT_LISTING_DEFAULT_SORT_ORDER is left blank
// for reverse, descending order use:
// $listing_sql .= " order by p.products_sort_order desc, pd.products_name";
$listing_sql .= " order by p.products_sort_order, pd.products_name";
break;
}
}
As far as I can see this loop is supposed to identify which column is the Product Name and use that for sorting, ascending.
Bug? : However the else clause has a break too, so this loop will only ever execute once and never identify the Product Name column unless it is the first column.
I made this change and it works, i.e. it iterates through all the columns and assigns the correct column id to the $_GET['sort'] for all positions of the Product Name
PHP Code:
for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
if (isset($column_list[$i]) && $column_list[$i] == 'PRODUCT_LIST_NAME') {//get the column with the PRODUCT_LIST_NAME in it and set the $_GET['sort'] to match its position
//$listing_sql .= " order by p.products_sort_order, pd.products_name";
break;//break out of the for loop when PRODUCT_LIST_NAME is found
}
}
// sort by products_sort_order when PRODUCT_LISTING_DEFAULT_SORT_ORDER is left blank
// for reverse, descending order use:
// $listing_sql .= " order by p.products_sort_order desc, pd.products_name";
$listing_sql .= " order by p.products_sort_order, pd.products_name";
3) Question
The next item in this code is:
PHP Code:
// if set to nothing use products_sort_order and PRODUCTS_LIST_NAME is off
if (PRODUCT_LISTING_DEFAULT_SORT_ORDER == '') {
$_GET['sort'] = '20a';
I cannot find where the second digit “0” is taken any account of…is this a typo and should be “2a”?
Bookmarks