Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

New "Quantity" sorting rule

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 11-23-2006, 09:47 AM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

Senior Member
  
Join Date: Jul 2005
Location: London, England.
Posts: 118
 

Default 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.
__________________
Apache/2.0.55 (Red Hat) & MYSQL Server: 5.0.24
PERL: 5.008005 / PHP: 4.4.4 - 4.3.1 X-CART

Shop carts at
http://www.nightscene.co.uk/shop/home.php
http://www.theshisha.net/shopcart/home.php
http://www.system-maintenance.com/maint/home.php
http://www.tabac4u.com
Reply With Quote
  #2  
Old 03-09-2007, 11:21 AM
 
robin robin is offline
 

Member
  
Join Date: Aug 2005
Location: Wilmington, NC
Posts: 13
 

Default 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?
__________________
X-cart Version: 4.1.3
PHP Version: 5.1.6
MySQL: 3.23.58
OS: Linux
Reply With Quote
  #3  
Old 04-18-2007, 12:15 AM
 
daveb1 daveb1 is offline
 

eXpert
  
Join Date: Sep 2003
Location: Brighton, UK
Posts: 222
 

Default 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
__________________
Quiet please... I'm trying to unscramble my brian.

http://lizzybug.co.uk (live, minor mods, 4.0.15)
EZCheckout/EZUpsell (Must have mods!) Firetank's Featured Products Manager, and loads of little mods off the forum (thanks all!)

http://www.jellybeangifts.co.uk (live, 4.0.18 ) Fancy Cats + custom colour mod
Reply With Quote
  #4  
Old 12-08-2007, 03:24 PM
  ShishaPipeUK's Avatar 
ShishaPipeUK ShishaPipeUK is offline
 

Senior Member
  
Join Date: Jul 2005
Location: London, England.
Posts: 118
 

Default 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.
__________________
Apache/2.0.55 (Red Hat) & MYSQL Server: 5.0.24
PERL: 5.008005 / PHP: 4.4.4 - 4.3.1 X-CART

Shop carts at
http://www.nightscene.co.uk/shop/home.php
http://www.theshisha.net/shopcart/home.php
http://www.system-maintenance.com/maint/home.php
http://www.tabac4u.com
Reply With Quote
  #5  
Old 03-30-2008, 01:20 PM
 
PuroPlacer PuroPlacer is offline
 

Advanced Member
  
Join Date: Jan 2007
Location: Marbella, Spain
Posts: 61
 

Default 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
__________________
PuroPlacer
X-Cart version
X-Cart Pro 4.1.5
Reply With Quote
  #6  
Old 03-30-2008, 07:58 PM
 
Nadeem Nadeem is offline
 

Advanced Member
  
Join Date: Sep 2006
Posts: 56
 

Default 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 ?
__________________
X-Cart 4.4.5 | Linux/Apache | PHP 5.2.17 | MySQL 5.0.77 | FireFox
Reply With Quote
  #7  
Old 07-15-2010, 03:23 AM
 
Learner Learner is offline
 

X-Adept
  
Join Date: Dec 2008
Posts: 807
 

Default Re: New "Quantity" sorting rule

For 4.3 versions???
__________________
4.6.1 Platinum


Reply With Quote
  #8  
Old 02-20-2013, 05:43 AM
  RichieRich's Avatar 
RichieRich RichieRich is offline
 

X-Adept
  
Join Date: Sep 2004
Location: London, England
Posts: 750
 

Default 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.
__________________
Richard


Ultimate 5.4 testing
Reply With Quote
  #9  
Old 03-31-2013, 12:41 AM
 
rodzok rodzok is offline
 

Advanced Member
  
Join Date: Apr 2008
Posts: 37
 

Default 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
__________________
2.35
Reply With Quote
  #10  
Old 01-23-2014, 08:53 AM
 
massjag massjag is offline
 

Newbie
  
Join Date: Aug 2013
Posts: 6
 

Default 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.
__________________
X-Cart Gold 4.6.1
Active store: anthonynappawines.com/xcart
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:20 PM.

   

 
X-Cart forums © 2001-2020