Products sorting by New or Date or timestamp

Hi 2.0.5 users,



How can I display products sorted by New or Date or timestamp? Where can I edit the product template? I have uploaded 10 products on 10 different dates. I have checked my database and confirmed timestamp field is different for each product.



It really annoying me to see the latest added product is displaying in a different location. Is there any solution for this?



Thanks,



CS Cart 2.0.5 User

[quote name=‘cm4554’]Hi 2.0.5 users,



How can I display products sorted by New or Date or timestamp? Where can I edit the product template? I have uploaded 10 products on 10 different dates. I have checked my database and confirmed timestamp field is different for each product.



It really annoying me to see the latest added product is displaying in a different location. Is there any solution for this?



Thanks,



CS Cart 2.0.5 User[/QUOTE]



Unfortunately bad news for you. This cart is not capable of this. I got one solution that was moved from 135 to 2.04 it still partly works.



It works like this



If you add today SKU010 to SKU020



They are going to be presented this way:



SKU010

SKU011

SKU012

SKU013

SKU014 and so on. But not by the actual time created.

SKU001

SKU002

SKU003

SKU004 these are added ex yesterday…



Checkout my site to see how it works

[url]http://www.truebalticamber.com/necklaces/[/url]

[quote name=‘cm4554’]Hi 2.0.5 users,



How can I display products sorted by New or Date or timestamp? Where can I edit the product template? I have uploaded 10 products on 10 different dates. I have checked my database and confirmed timestamp field is different for each product.



It really annoying me to see the latest added product is displaying in a different location. Is there any solution for this?



Thanks,



CS Cart 2.0.5 User[/QUOTE]



Hi,



I quickly took a look at this, i’m not sure where exactly you wanted the products sorted by date but in order sort the categories. go to



[root_folder] => contollers => customer => categories.php



around lines 67 add . . .



$params[‘sort_by’] = ‘timestamp’;



like so…



if (Registry::get('settings.General.show_products_from_subcategories') == 'Y') {
$params['subcats'] = 'Y';
}

[B]$params['sort_by'] = 'timestamp';[/B]

list($products, $search) = fn_get_products($params, Registry::get('settings.Appearance.products_per_page'));




change the order with



$params[‘sort_order’] = ‘asc’;



or



$params[‘sort_order’] = ‘desc’;



This worked on 2.0.4 it should work with 2.0.5, i can’t see it being any different.

Where do you add this $params[‘sort_order’] = ‘desc’; ?

You can add it right after the other line you added



$params[‘sort_by’] = ‘timestamp’;



Does it work well for you?

[quote name=‘twin892’]You can add it right after the other line you added



$params[‘sort_by’] = ‘timestamp’;



Does it work well for you?[/QUOTE]



Not tested it yet. One I use installs to core/fn.catalog.php



does it work for you ?

Thanks Darius and twin892…



I have added the following as described above.

$params[‘sort_by’] = ‘timestamp’;

$params[‘sort_order’] = ‘desc’; or $params[‘sort_order’] = ‘asc’;



That worked and shown the latest products asc / desc.

But the biggest problem was Sort by ‘Product’, ‘Price’ and ‘Default’ option was disabled, I mean didn’t work.



Is there any way to add professionally in the admin section as a drop down option along with the existing options?

Or if you have a local addon you can do it without any core source modifications at all…

For categories (the example given) you’d have a file called (using the ‘local’ addon for example).

addons/local/controllers/customer/categories.pre.php



This file would have content of

```php

$my_sort_params = array('sort_by' => 'timestamp', 'sort_order' => 'desc');
$_REQUEST = array_merge($_REQUEST, $my_sort_params);
?>

This will set the REQUEST variable add in or replace the existing values with what you want.

This is not debugged or verified code. It is an example of how things can be done without every modifying system files and hence avoiding upgrade hell....

You can get a [B]free[/B] "local" addon that will give you the basic structure for adding your own local modifications here: [url]http://www.ez-ms.com/local_addon_v2.tgz[/url]

Can someone make a proper addon of it? :slight_smile:

No need for an addon. Do you want to sort by timestamp in both back and front end or just the front end?

Yes, Can you please let me know how to do it?

Do you want to sort by timestamp in both back and front end or just the front end?

[quote name=‘Tool Outfitters’]Do you want to sort by timestamp in both back and front end or just the front end?[/QUOTE]



Front end. But timestamp sorts incorrect, if all products were added today so lowest product code will be first one in category not one latest added by hours…

Add this via admin in Design mode in /skins/your_skin/customer/views/products/components/sorting.tpl


```php



{$lang.sort_by}:

[COLOR=“Blue”]{$lang.newest} [/COLOR]

{$lang.product}{if $search.sort_by == “product”} {if $search.sort_order == “asc”}{else}{/if}{/if}

{$lang.price}{if $search.sort_by == “price”} {if $search.sort_order == “asc”}{else}{/if}{/if}

{$lang.default}

```

I know this method. It sorts but only temporary if you switch categories you must sort again.



I have a solution so newly listed are default sorting but problem is it displays products incorrect. I need a solution so the very very latest added product be on top of all others, as if I add today 1000 products the actual newest product (last to add) will be in unknown page…


[quote name=‘Tool Outfitters’]Add this via admin in Design mode in /skins/your_skin/customer/views/products/components/sorting.tpl


```php



{$lang.sort_by}:

[COLOR=“Blue”]{$lang.newest} [/COLOR]

{$lang.product}{if $search.sort_by == “product”} {if $search.sort_order == “asc”}{else}{/if}{/if}

{$lang.price}{if $search.sort_by == “price”} {if $search.sort_order == “asc”}{else}{/if}{/if}

{$lang.default}

```[/QUOTE]

[quote name=‘Darius’]Can someone make a proper addon of it? :)[/QUOTE]

Load the free addon from here: [url]http://www.ez-ms.com/local_addon_v2.tgz[/url].

Install it and then apply the *.pre.php controller hooks as needed.



Should take all of 1/2 hour.



tony

[quote name=‘Darius’]I know this method. It sorts but only temporary if you switch categories you must sort again.



I have a solution so newly listed are default sorting but problem is it displays products incorrect. I need a solution so the very very latest added product be on top of all others, as if I add today 1000 products the actual newest product (last to add) will be in unknown page…[/QUOTE]



So you want it to be default? If so, then you will have to do it in both front and back end. Post #11 [url]http://forum.cs-cart.com/showthread.php?p=52543#post52543[/url]



I’m not quite sure why you want it down to the hour, minute, second or whatever but I am not sure the cart is capable of that?

[quote name=‘Tool Outfitters’]No need for an addon. Do you want to sort by timestamp in both back and front end or just the front end?[/QUOTE]



User’s choice. Don’t use an addon and then you can spend hours resolving conflicts for each upgrade that comes out (while your store is closed I might add). Use an addon and your changes are independent of the core release and all you need to do is very that your modifications don’t break the core (or the core doesn’t break you).



I find most of the distributed template code almost unreadable. very little structure is used. Everything is crammed onto one line with embedded if statements, etc. So trying to find local changes and then retrofitting those to the standard (newly) upgraded files is a real pain. The ‘diff’ feature they have is very nice though with the color coding and all. But if there have been significant changes the “delta” can be quite large.



I’ve found that using addons wherever possible significantly reduces the upgrade time and most times I have maybe 3 files that have conflicts. I guess I’m just an addon-champion.

The first one may but the second definately will not. It’s all database related.

Any body got a professional solution?