Order Your Products & Categories
Location: Shortcut to Homepage / Free CubeCart 3 Mods / Order Your Products & Categories
Order Your Products & Categories

This is for CubeCart 3. 

Its actually really easy to change the order of your products & cats, as long as your happy with order ascending or descending by one of the fields already in the database, eg: name, time added (id), number of subcategories, price, etc.

To change the order of the top level categories (in the side box), you should edit: includes/boxes/categories.inc.php (backup first!)

To change the order of sub categories and/or product listings, you should edit: includes/content/viewCat.inc.php (backup first!)

Search for SELECT. This will take you to each of the database SQL queries. You can modify any of these (carefully) by appending ." ORDER BY xxx ASC" or ." ORDER BY xxx DESC", and ensure you keep the full stop, and the space before the word ORDER. In PHP, the full stop performs concatenation of strings.

E.g. To order top level categories alphabetically, modify the SQL SELECT query in categories.inc.php:

$results = $db->select("SELECT cat_name, cat_id FROM ".$glob['dbprefix']."CubeCart_category WHERE cat_father_id = 0" ." ORDER BY cat_name ASC");

E.g. To order subcategories alphabetically, make the same change to the first SQL SELECT in viewCat.inc.php:

$query = "SELECT * FROM ".$glob['dbprefix']."CubeCart_category WHERE cat_father_id = ".$db->mySQLSafe($_GET['catId']) ." ORDER BY cat_name ASC";

E.g. To order product listings so that the most expensive item is shown at the top, modify the third (search listing), fourth (sale items listing) and fifth (all other prod listings) SQL SELECT queries in viewCat.inc.php. I.e. For the fifth SQL SELECT query:

$productListQuery = "SELECT ".$glob['dbprefix']."CubeCart_cats_idx.cat_id, ".$glob['dbprefix']."CubeCart_cats_idx.productId, productCode, quantity, description, image, price, name, popularity, sale_price, stock_level, useStockLevel FROM ".$glob['dbprefix']."CubeCart_cats_idx INNER JOIN ".$glob['dbprefix']."CubeCart_inventory ON ".$glob['dbprefix']."CubeCart_cats_idx.productId = ".$glob['dbprefix']."CubeCart_inventory.productId WHERE ".$glob['dbprefix']."CubeCart_cats_idx.cat_id = ".$db->mySQLSafe($_GET['catId']) ." ORDER BY price DESC";

P.S. If you're ready for something more complicated, you could order product listings by ID descending, so that the most recently added product(s) are shown at the top. This is more complicated because the productId field occurs in both tables that are being used in the SQL query, so you have to indicate which table's productId field you wish to use (and in this case they are both the same so it doesn't really matter which one):

$productListQuery = "SELECT ".$glob['dbprefix']."CubeCart_cats_idx.cat_id, ".$glob['dbprefix']."CubeCart_cats_idx.productId, productCode, quantity, description, image, price, name, popularity, sale_price, stock_level, useStockLevel FROM ".$glob['dbprefix']."CubeCart_cats_idx INNER JOIN ".$glob['dbprefix']."CubeCart_inventory ON ".$glob['dbprefix']."CubeCart_cats_idx.productId = ".$glob['dbprefix']."CubeCart_inventory.productId WHERE ".$glob['dbprefix']."CubeCart_cats_idx.cat_id = ".$db->mySQLSafe($_GET['catId']) . " ORDER BY ".$glob['dbprefix']."CubeCart_cats_idx.productId DESC";

(Based on 2 Reviews)

  Add to Registry Add to Wish List Price: AU$0.00


  Related Products


Copyright © 2005 - 2011 Estelle WinterfloodVPS Hosting by Linode