There may be times when you need to remove the random function that is the default behaviour of the Featured Centerbox in Zen Cart and set a different sort order.
For example, I am currently developing a Zen Cart store for a client that has a total of four items for sale. And, as these items form a series, it makes sense to have all four items featured and appear in the correct order.
Follow the steps below for the Featured Products Centerbox to follow the sort order as set in Zen Cart Admin for each Product.

- Open the featured_products.php file located in the /includes/modules/ directory.
- Find this section of code:
$featured_products = $db->ExecuteRandomMulti($featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED);
- and change to:
$featured_products = $db->Execute($featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED);
- Next, find this section of code:
$featured_products->MoveNextRandom(); 
- and change to:
$featured_products->MoveNext(); 
- Now that we have removed the Random function, we will need to set the required sort order. In this instance, we are going to use the sort order that is set in Zen Cart Admin when adding each product.There are two ‘select’ statements towards the top of the featured_products.php file. You will need to modify both of these statements.At around line 22, find this section of code:
$featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id from (" . TABLE_PRODUCTS . " p left join " . TABLE_FEATURED . " f on p.products_id = f.products_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id ) where p.products_id = f.products_id and p.products_id = pd.products_id and p.products_status = 1 and f.status = 1 and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'"; - and change to:
$featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id from (" . TABLE_PRODUCTS . " p left join " . TABLE_FEATURED . " f on p.products_id = f.products_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id ) where p.products_id = f.products_id and p.products_id = pd.products_id and p.products_status = 1 and f.status = 1 and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' order by products_sort_order"; - Then locate the second ‘select’ statement (it’s around line 41):
$featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id from (" . TABLE_PRODUCTS . " p left join " . TABLE_FEATURED . " f on p.products_id = f.products_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id) where p.products_id = f.products_id and p.products_id = pd.products_id and p.products_status = 1 and f.status = 1 and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' and p.products_id in (" . $list_of_products . ")"; - and change to:
$featured_products_query = "select distinct p.products_id, p.products_image, pd.products_name, p.master_categories_id from (" . TABLE_PRODUCTS . " p left join " . TABLE_FEATURED . " f on p.products_id = f.products_id left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_id = pd.products_id) where p.products_id = f.products_id and p.products_id = pd.products_id and p.products_status = 1 and f.status = 1 and pd.language_id = '" . (int)$_SESSION['languages_id'] . "' and p.products_id in (" . $list_of_products . ") order by products_sort_order"; - Save the modified featured_products.php file to your override folder. This will be /includes/modules/CUSTOM/ where CUSTOM represents the name of your current template folder.
|
|||||||



