Set a sort order for the Featured Products Centerbox on Zen Cart Home Page


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.

Zen Cart Admin - Product Sort Order

  1. Open the featured_products.php file located in the /includes/modules/ directory.
  2. Find this section of code:
     $featured_products = $db->ExecuteRandomMulti($featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED);
  3. and change to:
    $featured_products = $db->Execute($featured_products_query, MAX_DISPLAY_SEARCH_RESULTS_FEATURED); 
  4. Next, find this section of code:
    $featured_products->MoveNextRandom();  
  5. and change to:
    $featured_products->MoveNext();  
  6. 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'] . "'";
  7. 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";
  8. 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 . ")";
  9. 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";
  10. 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.
     
   
     

,

More Zen Cart:

  1. Change the number of products displayed in the Featured Products centerbox in Zen Cart
  2. Display Featured Products on ‘Page Not Found’ page in Zen Cart
  3. Where/how to update the menu that has the options: “Home Page/New Products/Specials/All Products/Reviews/Contact Us/FAQ”?
  4. How do I exclude Free Products from the Bestsellers Sidebox in Zen Cart?
  5. Reset the Order ID number in Zen Cart
  1. No comments yet.
(will not be published)

Notify me of followup comments via e-mail. You can also subscribe without commenting.