Here is a custom modification for xcart 4.1.9 to add a Quantity sorting so that your products out of stock or low quantity can be shown last.
2 files to change and a sql patch
products.php
include/search.php
With the include/search.php find:
Code:
$sort_fields = array(
"productcode" => func_get_langvar_by_name("lbl_sku"),
"title" => func_get_langvar_by_name("lbl_product"),
"price" => func_get_langvar_by_name("lbl_price"),
"orderby" => func_get_langvar_by_name("lbl_default")
);
And replace all the code with:
Code:
$sort_fields = array(
"productcode" => func_get_langvar_by_name("lbl_sku"),
"title" => func_get_langvar_by_name("lbl_product"),
"price" => func_get_langvar_by_name("lbl_price"),
# ADD QUANTITY MOD TO SORT BY STOCK LEVELS
"quantity" => func_get_langvar_by_name("lbl_quantity"),
# END QUANTITY MOD TO SORT BY STOCK LEVELS
"orderby" => func_get_langvar_by_name("lbl_default")
);
With the
products.php find:
Code:
$search_data["products"] = array();
$search_data["products"]["categoryid"] = $cat;
$search_data["products"]["search_in_subcategories"] = "";
$search_data["products"]["category_main"] = "Y";
$search_data["products"]["category_extra"] = "Y";
$search_data["products"]["forsale"] = "Y";
if(!isset($sort))
$sort = $config["Appearance"]["products_order"];
if(!isset($sort_direction))
$sort_direction = 0;
And replace the full code with:
Code:
$search_data["products"] = array();
$search_data["products"]["categoryid"] = $cat;
$search_data["products"]["search_in_subcategories"] = "";
$search_data["products"]["category_main"] = "Y";
$search_data["products"]["category_extra"] = "Y";
$search_data["products"]["forsale"] = "Y";
if(!isset($sort))
$sort = $config["Appearance"]["products_order"];
# if(!isset($sort_direction))
# ADD MOD FOR SORTING BY STOCK LEVELS
if(!isset($sort_direction) && $sort == 'quantity')
$sort_direction = 1;
elseif(!isset($sort_direction))
# END MOD SORTING BY STOCK LEVELS
$sort_direction = 0;
Apply the SQL changes (Open the Patch/Upgrade page in admin area and select the patch.sql from the archive for the "Apply SQL patch" section).
Code:
UPDATE xcart_config SET value='quantity', variants='productcode:lbl_sku\r\ntitle:lbl_product\r\norderby:lbl_default\r\nprice:lbl_price\r\nquantity:lbl_quantity' WHERE name='products_order';
UPDATE xcart_modules SET active='N' WHERE moduleid='87';
You can see this working at
http://www.shishapipe.net/shopcart/home.php?cat=280 - You will see the products i have a lot of stock shows first then at the end are the out of stock products.