Adding Product Code To Default Sorting

I have been searching for this off and on for some time now and I just happened upon it trying to correct the timezone issue. It’s funny how some things are so easy to change but the challenge is finding out where to make the changes.



What this does is add default sorting for product code. It isn’t complete because I have yet to determine how to add “Product Code” to the selection list in Appearance Settings, however, it still sorts your products by code.



In myphpadmin in the database table cscart_settings_variants you simply need to add the option as show in the pic below.



[ATTACH]789[/ATTACH]





Like I said, Product code does not show up in the list but if you select the blank, your products will be sorted by code both in admin and in customer area.



[ATTACH]790[/ATTACH]



I can’t believe that CS-Cart architects have not implemented this? It’s not that difficult and they know where things are located better than we do. Also, I am sure it’s been requested at least a few times.

sorting1.jpg

sorting.jpg

Add to cscart_settings_descriptions



object_id = 10007

description = Product code

object_type = V

lang_code = EN

Thanks Matt, I was busy working on other stuff but that was where I was headed next.



For others, Matts suggestion adds the “Product code” to the selection list in admin.

[quote name=‘mdekok3000’]Add to cscart_settings_descriptions



object_id = 10007

description = Product code

object_type = V

lang_code = EN[/QUOTE]



Any chance someone could be specific about where to locate this code and how to implement it. This would solve a huge problem for me. Sorry to be a pain but I know just enough about what I am doing to get in a serious fix. Thanks!!

[quote name=‘Tool Outfitters’]I have been searching for this off and on for some time now and I just happened upon it trying to correct the timezone issue. It’s funny how some things are so easy to change but the challenge is finding out where to make the changes.



What this does is add default sorting for product code. It isn’t complete because I have yet to determine how to add “Product Code” to the selection list in Appearance Settings, however, it still sorts your products by code.



In myphpadmin in the database table cscart_settings_variants you simply need to add the option as show in the pic below.



[ATTACH]789[/ATTACH]





Like I said, Product code does not show up in the list but if you select the blank, your products will be sorted by code both in admin and in customer area.



[ATTACH]790[/ATTACH]



I can’t believe that CS-Cart architects have not implemented this? It’s not that difficult and they know where things are located better than we do. Also, I am sure it’s been requested at least a few times.[/QUOTE]



How do you insert the necessary field in the database. I see the insert tab but do not know what to do after that. Thanks for any and all help.

[quote name=‘davidwpotts@bellsouth.net’]How do you insert the necessary field in the database. I see the insert tab but do not know what to do after that. Thanks for any and all help.[/QUOTE] I have figured out how to insert the necessary fields in the datbase. Unfortunately, I ended up with unusable results. It started sorting products like so:



10

101

102…

20

201…etc



Completely unusable. :frowning:

I don't know what you are selling david but if you have a lot of different manufacturers, sorting by product code keeps your products more organized.

[quote name=‘Tool Outfitters’]I don’t know what you are selling david but if you have a lot of different manufacturers, sorting by product code keeps the your products more organized.



You can have a look at tooloutfitters.net.[/QUOTE]



Good looking site. Liked the listmania layout on the homepage. Looks much better than the default settings. I will definately change mine.



I am selling comic books. Over 11,000 listed currently with literally hundreds of manufacturers/publishers. I upload new products using a spread sheet since I list 100’s at a time and this is much quicker.



I have been sorting my items with the default settings which does work, although without going into a lengthy explanation, problems do arise. Sorting by product code would be perfect. Thing is, when I add new products in numeric order on the spread sheet they do not show in correct position on the site. Any new item is listed at the very end of the page. Example:



If I have products codes 1,2 3 5,6 and I add product code 4 the end result is 1,2,3,5,6,4 on my site. Even if I insert 4 in proper postion in the spreadsheet.



Thanks for you time!

Something isn’t right if it isn’t sorting numerically. It sounds as if is still sorting by id/when added?



Did you “Update” after selecting “Product code”?

This works for version 2 as well.

[quote name=‘Tool Outfitters’]This works for version 2 as well.[/QUOTE]



Well I stand corrected. This was working with the beta version but is no longer working with the “stable” version.



Edit: It doesn’t seem that any of the other sorting options work either.

[quote name=‘Tool Outfitters’]This works for version 2 as well.[/QUOTE]





Dear Tool Outfitters,



How to do with the added date or time stamp?

Try this for sorting by date added:



In cscart_settings_descriptions insert:



object_id = 10008

description = Date added

object_type = V

lang_code = EN



In cscart_settings_variants insert:



variant_id = 10008

option_id = 10035

variant_name = timestamp

position = 40

[quote name=‘Tool Outfitters’]Try this for sorting by date added:



In cscart_settings_descriptions insert:



object_id = 10008

description = Date added

object_type = V

lang_code = EN



In cscart_settings_variants insert:



variant_id = 10008

option_id = 10035

variant_name = timestamp

position = 40[/QUOTE]



Hi, as this method, all products are sort from olded to newest, how to make it sort from newest to oldest ?



in other topic, I see this:Please find this part of the code:
Code:

if (empty($sort_order) || empty($directions[$sort_order])) {
$sort_order = 'desc';
}

in the "search_products.php" file located in the "include/common" directory of your CS-Cart and replace "desc" with "asc".




But can not find search_products.php in cscart 2.0.



Thanks for your help !

[quote name=‘michael’]Hi, as this method, all products are sort from olded to newest, how to make it sort from newest to oldest ?



in other topic, I see this:Please find this part of the code:
Code:

if (empty($sort_order) || empty($directions[$sort_order])) {
$sort_order = 'desc';
}

in the "search_products.php" file located in the "include/common" directory of your CS-Cart and replace "desc" with "asc".




But can not find search_products.php in cscart 2.0.



Thanks for your help ![/QUOTE]

That version is 1.3.X…

[quote name=‘joe’]That version is 1.3.X…[/QUOTE]



I know, so, I wanna know how to apply this in 2.0, thanks.

Anyone knows ?

I do not have timestamp/date added set up in mine so test it and let me know.



In /core/fn_catalog.php add the part in [COLOR=“Blue”]blue[/COLOR]


$join .= " INNER JOIN ?:products_categories as products_categories ON products_categories.product_id = products.product_id INNER JOIN ?:categories ON ?:categories.category_id = products_categories.category_id $avail_cond $feature_search_condition";
$limit = '';
$group_by = 'products.product_id';
fn_set_hook('get_products', $params, $fields, $sortings, $condition, $join, $sorting, $group_by);

if (empty($params['sort_order']) || empty($directions[$params['sort_order']])) {
$params['sort_order'] = '[COLOR="Blue"]desc[/COLOR]';
}

if (empty($params['sort_by']) || empty($sortings[$params['sort_by']])) {
$params['sort_by'] = Registry::get('settings.Appearance.default_products_sorting');
}

if ($params['type'] != 'extended' && $params['sort_by'] == 'price') {
$params['sort_by'] = 'product';
}

$sorting = $sortings[$params['sort_by']] . ' ' . $directions[$params['sort_order']];

I did try this with “Product code” instead of “Date added” (because I don’t need it) and it does work. This is, of course, you made the changes above in the database for Date added/timestamp and it sorts from newest to oldest.

This worked well in version 2.0.6, but did not worked in latest version 2.0.8

Can anyone got an advice?