X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   New "Quantity" sorting rule (https://forum.x-cart.com/showthread.php?t=26847)

ShishaPipeUK 11-23-2006 09:47 AM

New "Quantity" sorting rule
 
Here is a custom modification for xcart 4.1.3 to add a Quantity sorting so that your products out of stock or low quantity can be shown last or 1st, which ever you want.

2 files to change and a sql patch

products.php
include/search.php

With the
include/search.php find:

Code:


"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 with:

Code:


"productcode" => func_get_langvar_by_name("lbl_sku"),
"title" => func_get_langvar_by_name("lbl_product"),
"price" => func_get_langvar_by_name("lbl_price"),
"quantity" => func_get_langvar_by_name("lbl_quantity"),
"orderby" => func_get_langvar_by_name("lbl_default")
);


With the products.php find:

Code:


$search_data["products"]["category_extra
$search_data["products"]["forsale"] = "Y";
if(!isset($sort))
$sort = $config["Appearance"]["products_order"];
if(!isset($sort_direction))
$sort_direction = 0;
 
$mode = "search";


Replace with:

Code:


$search_data["products"]["category_extra
$search_data["products"]["forsale"] = "Y";
if(!isset($sort))
$sort = $config["Appearance"]["products_order"];
if(!isset($sort_direction) && $sort == 'quantity')
$sort_direction = 1;
elseif(!isset($sort_direction))
$sort_direction = 0;
 
$mode = "search";


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';


Thats it.

robin 03-09-2007 11:21 AM

Re: New "Quantity" sorting rule
 
This is a great mod and works perfectly for the search function. How could I get the same sort functionality for a regular product list page?

daveb1 04-18-2007 12:15 AM

Re: New "Quantity" sorting rule
 
I'm having this problem with a 4.0.19 site. Is there an equivalent mod for this version?

Cheers

ShishaPipeUK 12-08-2007 03:24 PM

Re: New "Quantity" sorting rule
 
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.

PuroPlacer 03-30-2008 01:20 PM

Re: New "Quantity" sorting rule
 
This is a great mod, thanks!
Only problem I have is when the product has variants, it will go to the back as well
Any ideas to solve this?

Would it be possible in some way to move JUST the "out of stock" to the back to the list, and keep the original ranking system of the products?

Thanks again :)

Nadeem 03-30-2008 07:58 PM

Re: New "Quantity" sorting rule
 
UPDATE xcart_modules SET active='N' WHERE moduleid='87';

i dont have any module with ID = 87 !
what is tha module name ?

Learner 07-15-2010 03:23 AM

Re: New "Quantity" sorting rule
 
For 4.3 versions???

RichieRich 02-20-2013 05:43 AM

Re: New "Quantity" sorting rule
 
Is any method for latest 4.5x branch? This is a great idea. The customer will see the product which has most quantity first. And put the low or out of stock last.

rodzok 03-31-2013 12:41 AM

Re: New "Quantity" sorting rule
 
can you please help me
i have 4.5.5 version and i need to sort the list of variant and show the out of stock at end of the row . what i mean is when one color is out of stock then that color will be shown as last option in variant list . do you have a code for this

massjag 01-23-2014 08:53 AM

Re: New "Quantity" sorting rule
 
Quote:

Originally Posted by RichieRich
Is any method for latest 4.5x branch? This is a great idea. The customer will see the product which has most quantity first. And put the low or out of stock last.


Did you ever come up with a solution for this in 4.5 or 4.6? We are running 4.6.1 and would love to be able to sort by qty so that sold out items appear last in the list.


All times are GMT -8. The time now is 09:27 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.