This got my attention and I decided to do it... Here's what you need to do.
Go to includes/index_filters/ and create a new directory for your template override and copy the default_filter.php to the new directory. Now you'll have something like includes/index_filters/YOUR_TEMPLATE/default_filter.php
Now edit that file and find around line 94
Code:
if (isset($column_list)) {
Add after:
Code:
// BOF randomize sort order 1/2
if ($_GET['sort'] == 'RAN') {
$seed = preg_replace("/[^0-9]/", "", $_SESSION['securityToken']);
$seed = substr($seed, 0, 5);
$seed = (int)$seed;
echo $seed;
$listing_sql .= " order by p.products_sort_order desc, rand($seed)";
} else {
// EOF randomize sort order 1/2
Next, around line 148 find 3 closing brackets and just add one more.
This is how your code will look:
Code:
// set the default sort order setting from the Admin when not defined by customer
if (!isset($_GET['sort']) and PRODUCT_LISTING_DEFAULT_SORT_ORDER != '') {
$_GET['sort'] = PRODUCT_LISTING_DEFAULT_SORT_ORDER;
}
if (isset($column_list)) {
// BOF randomize sort order 1/2
if ($_GET['sort'] == 'RAN') {
$seed = preg_replace("/[^0-9]/", "", $_SESSION['securityToken']);
$seed = substr($seed, 0, 5);
$seed = (int)$seed;
echo $seed;
$listing_sql .= " order by p.products_sort_order desc, rand($seed)";
} else {
// EOF randomize sort order 1/2
if ((!isset($_GET['sort'])) || (isset($_GET['sort']) && !preg_match('/[1-8][ad]/', $_GET['sort'])) || (substr($_GET['sort'], 0, 1) > sizeof($column_list)) ) {
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;
}
}
// if set to nothing use products_sort_order and PRODUCTS_LIST_NAME is off
if (PRODUCT_LISTING_DEFAULT_SORT_ORDER == '') {
$_GET['sort'] = '20a';
}
} else {
$sort_col = substr($_GET['sort'], 0 , 1);
$sort_order = substr($_GET['sort'], 1);
switch ($column_list[$sort_col-1]) {
case 'PRODUCT_LIST_MODEL':
$listing_sql .= " order by p.products_model " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
case 'PRODUCT_LIST_NAME':
$listing_sql .= " order by pd.products_name " . ($sort_order == 'd' ? 'desc' : '');
break;
case 'PRODUCT_LIST_MANUFACTURER':
$listing_sql .= " order by m.manufacturers_name " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
case 'PRODUCT_LIST_QUANTITY':
$listing_sql .= " order by p.products_quantity " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
case 'PRODUCT_LIST_IMAGE':
$listing_sql .= " order by pd.products_name";
break;
case 'PRODUCT_LIST_WEIGHT':
$listing_sql .= " order by p.products_weight " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
case 'PRODUCT_LIST_PRICE':
$listing_sql .= " order by p.products_price_sorter " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
break;
}
}
// BOF randomize sort order 2/2
}
// EOF randomize sort order 2/2
}
// optional Product List Filter
if (PRODUCT_LIST_FILTER > 0) {
Next, go to your admin->Configuration->Product Listing and set "Display Product Listing Default Sort Order" to RAND.
Don't get confused with the code above using 'RAN' - this is on purpose because the very beginning of the default_filter.php strips the $_GET parameter down to 3 characters... Basically, you can enter RANDOM in the admin, it won't make any difference. Heck, you could even put RANCH...
There's no mention of duplicate content since the sort order is passed on to all pages and products will not be duplicated. It will only randomize the sort order based on session parameter which is randomly generated by Zen Cart...
Bookmarks