Page 1 of 2

[HOW TO] Change Default Product Sort Order

Posted: Wed Dec 30, 2009 6:10 am
by Skyhigh
By default when a category is viewed the sort order is "By Name A-Z".

This isn't always the best option, I've changed the default sort order of the LoveMoissanite.com store to be by Rating (Highest First) - which makes a bit more sense, since you want visitors to see the highest-rating items first, since these are likely to be your most popular products.

By default, for items with no rating - they are shown by Product ID order, the order you've added them to your shop.
(this is also helpful, since usually you'll add different versions of the same item, or related items one after another).

So, example:
http://www.lovemoissanite.com/Moissanit ... -Brilliant


It's really really simple to do.

Open up:
\catalog\controller\product\category.php


Line 64 forward:

Code: Select all

			if (isset($this->request->get['sort'])) {
				$sort = $this->request->get['sort'];
			} else {
			           //	$sort = 'pd.name';
			             $sort = 'rating'; // sort by rating by default
			}

			if (isset($this->request->get['order'])) {
				$order = $this->request->get['order'];
			} else {
				   //$order = 'ASC';
				   $order = 'DESC';	// sort rating Descending by default
			}

All I've done is comment out the original Sort type and Sort order, and replace them with "rating" and "DESC".

Additionally, as OpenCart is built so well, the "sort" drop down on your site will also now default to show "Rating (highest first)"


Done :)

Re: [HOW TO] Change Default Product Sort Order

Posted: Thu Dec 31, 2009 8:29 am
by deeve
Very interesting! I've been asking on here if anyone knew of a way to change the default view of products in Category pages to Latest Products. It appears from this How To that on the surface, a 'Lowest Ratings' option would achieve the same result.

However, I wouldn't want my client's customers to see his products as being Lowest Rated [he doesn't actually have a use for the Ratings Feature itself as his products are mostly one-offs] but wondered if it were as simple to change the wording on the drop-down menu to 'Latest Arrivals' and to delete the ratings feature itself from all other pages [Product Description List & Review Tab]?

Possible?

Re: [HOW TO] Change Default Product Sort Order

Posted: Thu Dec 31, 2009 5:06 pm
by deeve
Actually implemented the following thread's advice:

http://forum.opencart.com/viewtopic.php ... s&start=15

& have managed to successfully remove all references to 'Reviews' throughout site.
Also have utilized $rating_ASC to sort the initial Category's Products list & changed $text_rating_ASC to 'Latest Arrivals' in drop-down Select box. However, would now need to remove the $text_rating_DESC option & am not sure were to comment out.

Any suggestions?

Re: [HOW TO] Change Default Product Sort Order

Posted: Tue Jan 26, 2010 4:58 pm
by deeve
Thought I'd add; since changing the sort order as above, I experience a weird anomaly if I then change the number of items which appear on the page in category.php in controller [+pagination to match]. It seems to throw the order right out of whack & can't seem to find a reason in the spreadsheet as nothing has changed there.

Any ideas anyone?

Re: [HOW TO] Change Default Product Sort Order

Posted: Tue Jan 26, 2010 9:29 pm
by deeve
Just had a thought; is it possible to hard code to sort buy 'product_id' instead of relying on the default method?

Re: [HOW TO] Change Default Product Sort Order

Posted: Tue Sep 28, 2010 1:20 pm
by Seven
How do you do this in 1.4.9.1? It looks like the default sort order is either product ID or date/time added. I'd like all my categories to list the products by 'Name A-Z' by default.

Re: [HOW TO] Change Default Product Sort Order

Posted: Tue Oct 05, 2010 9:01 pm
by Seven
I took a fresh look at this and made a change similar to Skyhigh's recommendation so that categories would sort by 'Name A-Z' instead of 'Default'. It works this way just fine, but was wondering if the more correct modification would be to change the definition of 'Default' (which I believe is product_id for 1.4.9.1, but please correct me if I'm wrong).

Or, is it really a '6 of one and 1/2 a dozen of the other' type thing?

Re: [HOW TO] Change Default Product Sort Order

Posted: Wed Aug 17, 2011 9:15 am
by shiokguy
Dear

I am using 1.5.1.1,
I want to change the sort order for category to model, desc.

My model is 4 digit code 1000 - 9999 where 1000 is the oldest products while 9999 is the latest.
I want to sort by default 9999 - 1000.

Please help.

Regards
Shiok Guy

Re: [HOW TO] Change Default Product Sort Order

Posted: Mon Oct 24, 2011 5:51 am
by stonehinged
What about sort by product stock status so in-stock product is always offered first? Ideas?

Re: [HOW TO] Change Default Product Sort Order

Posted: Mon Oct 24, 2011 6:26 am
by stonehinged
Figured this out just now I think.

Code: Select all

if (isset($this->request->get['sort'])) {
				$sort = $this->request->get['sort'];
			} else {
				// $sort = 'pd.name';
				$sort = 'quantity';	  // changed to quantity so product w/stock sorted to top
			}

			if (isset($this->request->get['order'])) {
				$order = $this->request->get['order'];
			} else {
				$order = 'DESC';  // changed to DESC so product w/stock sorted to top
			}
I've also added the sort by selection in the menu if anyone is interested.

Re: [HOW TO] Change Default Product Sort Order

Posted: Sat Nov 12, 2011 1:02 am
by lmb500
stonehinged wrote:Figured this out just now I think.

Code: Select all

if (isset($this->request->get['sort'])) {
				$sort = $this->request->get['sort'];
			} else {
				// $sort = 'pd.name';
				$sort = 'quantity';	  // changed to quantity so product w/stock sorted to top
			}

			if (isset($this->request->get['order'])) {
				$order = $this->request->get['order'];
			} else {
				$order = 'DESC';  // changed to DESC so product w/stock sorted to top
			}
I've also added the sort by selection in the menu if anyone is interested.


Hello, thank you for writing up the code to arrange by quantity in categories. Can this also be done while viewing by manufacturer.

I tried editing the manufacturer.php, but this did not affect anything.

Re: [HOW TO] Change Default Product Sort Order

Posted: Fri Dec 02, 2011 8:42 am
by watchuniverse
Hello,

I am fairly new at this so if it seems I am asking a stupid question I apologize, but, I have just tried to insert the code for sorting by quantity but it has not done anything. Do i need to do anything else apart from copying the above code into line 64?? Any help would be useful. (also if you can show me a "cut out" i.e. a few lines of text before, so that I know for sure I have put the code in the right place that would also help me out alot :) Also for me it do not need this to be the default option I just want to have it in the drop down menu so my clients can use it when necessary.

Thanks in advance

Thanks in advance.

Re: [HOW TO] Change Default Product Sort Order

Posted: Tue Dec 27, 2011 1:09 am
by sohbrandon
Hi anyone, I like to know how to change or the numbering of order id and the invoice id. Anyone there can guide me? :choke:

Re: [HOW TO] Change Default Product Sort Order

Posted: Tue Jan 29, 2013 12:42 am
by egejo
Please I'm trying to do a product sorting by quantity in stock first in my web page www.splatwar.com that is running 1.5.4
I have edited category.php according to what is stated in these post but nothing happens or changes at all. I also edited further to text_quanitity and in other parts of the php file where I could read something regarding the default sorting but I'm not and expert on php and dont know exactly what to do.

As I can see on dates and everything these post should was created for 1.4 as also my catalog.php file has a different structure and on line 64 I have a complete different line.

So please please please can someone help me resolving these for my 1.5.4 store. I really need the products on stock to be showed first to all my clients and then the ones without stock or preorders now everything is mixed and ugly.

Also these should be a regular sorting method on open cart as it seams the more logical one.

Re: [HOW TO] Change Default Product Sort Order

Posted: Thu Feb 21, 2013 11:39 pm
by otd
is it possible to sort by name and then also by price. So if 2 products have the same name then it sorts them both by price (lowest being first)?

Re: [HOW TO] Change Default Product Sort Order

Posted: Sat Mar 09, 2013 9:24 am
by stonehinged
I'm now on 1.5.2.1 but found my original post was not quite the way to do this.

I'm now doing the following using a vqmod:

Code: Select all

<file name="catalog/controller/product/category.php">
		<operation>
			<search position="replace"><![CDATA['href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url)]]></search>
			<add><![CDATA['href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.quantity&order=DESC' . $url)]]></add>
		</operation>
	</file>
This changes the default sort by greatest quantity in stock first. The only trouble is it seems to also treat product name as DESC as well. I'd love if the product name could still be ASC.

Re: [HOW TO] Change Default Product Sort Order

Posted: Wed Apr 03, 2013 11:44 am
by trenttdogg
Can anyone tell me how I can remove the Model (A-Z) and Model (Z-A) from the sort drop down on the category pages?

Thanks,

Re: [HOW TO] Change Default Product Sort Order

Posted: Tue Aug 19, 2014 5:32 am
by lexyy
Hello, i'm new one, I'm using Opencart ver. 1.5.6 and i wanted to change the default sorting of products in categories - the last added products to be first. And this is what i've done:
In catalog/controller/product/category.php
at line 21 change

Code: Select all

$sort = 'p.sort_order'; 
to this

Code: Select all

$sort = 'p.date_added';
at line 27 change

Code: Select all

$order = 'ASC';
to this

Code: Select all

$order = 'DESC';
at line 266 change this

Code: Select all

'value' => 'p.sort_order-ASC',
href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url)
to this

Code: Select all

'value' => 'p.date_added-ASC',
href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.date_added&order=ASC' . $url)
And to remove sorting by Model(A-Z) and Model(Z-A)
remove this code from line 308

Code: Select all

			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_model_asc'),
				'value' => 'p.model-ASC',
				'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=ASC' . $url)
			);

			$this->data['sorts'][] = array(
				'text'  => $this->language->get('text_model_desc'),
				'value' => 'p.model-DESC',
				'href'  => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=DESC' . $url)
			);
Hope to help someone.

Re: [HOW TO] Change Default Product Sort Order

Posted: Sun Sep 21, 2014 1:42 pm
by ajmery
Hello,

can any one tell me that how can i change the sort order for manufacturer page, i want newest uploaded product on top

Please help me

Re: [HOW TO] Change Default Product Sort Order

Posted: Fri Dec 26, 2014 7:40 am
by ozkiremitci
hi all,

How to multiple sort ?

e.g. Products with similar products of the same brand before after...

How can I give you an idea?