Post by hecticben » Wed Mar 12, 2014 8:36 am

Hey guys,

I've googled how to solve this, but all solutions have been for older versions of OpenCart, where the code is different...

Basically my products are currently displaying alphabetically.. I want them to display in the order I add them (date added).. can anyone help?

Many thanks!

New member

Posts

Joined
Sun Jan 19, 2014 11:03 pm

Post by billynoah » Wed Mar 12, 2014 3:20 pm

And what version of OpenCart might you be using? And where do you mean? On category pages? In Search Results? In menus?

In the Admin panel list? In the store front?

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by hecticben » Wed Mar 12, 2014 7:44 pm

Hey there,

Thanks for the reply..

I'm using 1.5.6 and I mean store front.. all products are listed alphabetically rather than date added.

New member

Posts

Joined
Sun Jan 19, 2014 11:03 pm

Post by billynoah » Thu Mar 13, 2014 12:00 am

I'd love to help but you still haven't completely answered my question. Products appears in the store front in many places.

menus
search results
category pages
featured list
specials page

and so on.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by hecticben » Thu Mar 13, 2014 12:03 am

Sorry buddy,

I'm talking about when you go into a category..

So Threads > Cotton Threads .. then the products show alphabetically..

New member

Posts

Joined
Sun Jan 19, 2014 11:03 pm

Post by billynoah » Thu Mar 13, 2014 12:18 am

Line 196 of catalog/model/catalog/product.php determines the field used for default sort order. It reads:

Code: Select all

$sql .= " ORDER BY p.sort_order";
You could simply change it to:

Code: Select all

$sql .= " ORDER BY p.date_added";

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by hecticben » Thu Mar 13, 2014 12:23 am

That doesn't seem to have made any difference.. still showing alphabetically..

New member

Posts

Joined
Sun Jan 19, 2014 11:03 pm

Post by billynoah » Thu Mar 13, 2014 12:39 am

Ah yes, that changes the default sort order but category pages specifically ask for sort_order on lin e21 of catalog/controller/product/category.php. Change:

Code: Select all

$sort = 'p.sort_order';
to

Code: Select all

$sort = 'p.date_added';
that should do it. if you want sort order changed on other pages you can make a similar change in the relevant controller request.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by hecticben » Thu Mar 13, 2014 12:57 am

Nop :/ still in alphabetical order lol

New member

Posts

Joined
Sun Jan 19, 2014 11:03 pm

Post by billynoah » Thu Mar 13, 2014 1:20 am

works for me. you either changed the wrong line or you aren't using a standard 1.5.6 install

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by hecticben » Thu Mar 13, 2014 1:25 am

I notice the template files also have order lines similar to the ones you asked me to change.. could these have anything to do with it?

New member

Posts

Joined
Sun Jan 19, 2014 11:03 pm

Post by billynoah » Thu Mar 13, 2014 1:56 am

probably not. the sort in the tpl typically relates to user selected sort options like, sort by price, rating, etc. unless you're seeing "sort" in the url query then the model should use the default which is what we set above. if you want inbox your site details and i'll take a look for you.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by hecticben » Thu Mar 13, 2014 2:12 am

Thanks! Very kind, will do now.

New member

Posts

Joined
Sun Jan 19, 2014 11:03 pm

Post by erlee » Tue Aug 05, 2014 8:43 pm

billynoah wrote:I'd love to help but you still haven't completely answered my question. Products appears in the store front in many places.

menus
search results
category pages
featured list
specials page

and so on.

ANy idea where i can change the SORT order for the FEATURED List..?
most of the solutions discussed here are for older versions of OC

Newbie

Posts

Joined
Sat Jul 12, 2014 9:17 pm

Post by billynoah » Tue Aug 05, 2014 9:13 pm

Not sure what you mean - solutions here are for 1.5.6 which is the newest version.

Featured doesn't use a sort order, it gets products in the order they appear in the extension, i.e., the order you added them. Easiest way would be to change the order you added them in. If you have lots of products already added and prefer to do this programmatically you could assign a key based on product info to the $this->data['products'] array and then use ksort or krsort to sort the array. For instance, to sort by product model instead of:

Code: Select all

$this->data['products'][] = array(
do:

Code: Select all

$this->data['products'][$product_info['model']] = array(
and then when loop is complete

Code: Select all

$this->data['products'] = ksort($this->data['products']);

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by peecha85 » Sat Sep 27, 2014 4:54 am

Is there a way to sort products by name AND THEN by model? I have perfume store, and it doesn't look nice when three the same name perfumes are listed like this in category:
Armani Code 75ml
Armani Code 30ml
Armani Code 50ml
(where Armani Code is 'Product name' and 75ml is 'Model').

I don't know what causes this kind of sorting.

I would like to see them listed like this:
Armani Code 30ml
Armani Code 50ml
Armani Code 75ml

Any ideas?

p.s.
still using 1.5.1. version

Active Member

Posts

Joined
Tue May 11, 2010 10:28 pm

Post by lesliez » Fri Apr 07, 2017 1:33 pm

Hi,

Can help the same (product listing after click category) for Latest product first for OC version 2.3.0.2? Please advice, thank you.

Lesz

Newbie

Posts

Joined
Sat Nov 20, 2010 12:48 pm
Who is online

Users browsing this forum: No registered users and 285 guests