Post by avd » Tue Jan 12, 2010 11:47 pm

Hi,

Just like to say a big hello to everyone and really enjoying using opencart really easy to install and setup.

Been looking around the forum for the past hour and cant find a solution for this, i would really like to sort the products in a category by the latest added by default instead of by a-z. i have 1.3.4 installed.

I have been trying all sorts to change /catalog/controller/product/category.php but with no luck as i dont know what im doing lol.

Thanks

avd
Newbie

Posts

Joined
Tue Jan 12, 2010 11:35 pm

Post by avd » Wed Jan 13, 2010 10:03 pm

Hey guys theres gotta be someone who knows how to do this please.

avd
Newbie

Posts

Joined
Tue Jan 12, 2010 11:35 pm

Post by avd » Fri Jan 15, 2010 9:19 pm

since no one has offered a solution for this can anyone point me in the direction of someone i can pay to tell me how to do this?

Thanks

avd
Newbie

Posts

Joined
Tue Jan 12, 2010 11:35 pm

Post by Xsecrets » Fri Jan 15, 2010 10:18 pm

edit /catalog/model/catalog/product.php

in fuction getProductsByCategoryId

around line 27 in my file change

Code: Select all

if (in_array($sort, $sort_data)) {
			$sql .= " ORDER BY " . $sort;
		} else {
			$sql .= " ORDER BY pd.name";	
		}
to

Code: Select all

if (in_array($sort, $sort_data)) {
			$sql .= " ORDER BY " . $sort;
		} else {
			$sql .= " ORDER BY p.date_added, pd.name";	
		}
and in catalog/controller/product/category.php

around line 70 change

Code: Select all

if (isset($this->request->get['order'])) {
				$order = $this->request->get['order'];
			} else {
				$order = 'ASC';
			}
to

Code: Select all

if (isset($this->request->get['order'])) {
				$order = $this->request->get['order'];
			} else {
				$order = 'DESC';
			}

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by Qphoria » Fri Jan 15, 2010 10:28 pm

Would be nice if there was some way to create "sort" options the same way order statuses and out of stock statuses are created. Then you could create additional sorts, and bring back the sort_order field in product to create a "default sort" option

The last part should happen anyway

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by avd » Fri Jan 15, 2010 10:52 pm

Hi,

Thank you so much for the advice, i have done what you have posted but the order is not by latest products. The order has change tho lol.

avd
Newbie

Posts

Joined
Tue Jan 12, 2010 11:35 pm

Post by Xsecrets » Fri Jan 15, 2010 11:11 pm

avd wrote:Hi,

Thank you so much for the advice, i have done what you have posted but the order is not by latest products. The order has change tho lol.
so what is it sorted by? that change should sort it by the date_added field from the database, which should = latest products.

Note: I didn't test this, so there could be some other influence coming from somewhere.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by avd » Sat Jan 16, 2010 12:26 am

Hi,

It ordered the products from z-a when you go in to a category.

avd
Newbie

Posts

Joined
Tue Jan 12, 2010 11:35 pm

Post by Xsecrets » Sat Jan 16, 2010 12:45 am

ah ok I see it now.

in catalog/controller/product/category.php
around line 64 change

Code: Select all

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

Code: Select all

if (isset($this->request->get['sort'])) {
				$sort = $this->request->get['sort'];
			} else {
				$sort = 'p.date_added';
			}
and in /catalog/model/catalog/product.php
around line 18 change

Code: Select all

		$sort_data = array(
			'pd.name',
			'p.price',
			'rating'
		);
to

Code: Select all

		$sort_data = array(
			'pd.name',
			'p.price',
			'rating',
         'p.date_added'
		);

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by avd » Sat Jan 16, 2010 1:09 am

Hi,

All sorted thank you very much the both of you. I had worked it out by myself and was gonna post the new code up.

Hey whats that last bit of code for as it doesnt seem to change anything.

oh and i was wondering if i can get rid of the sort by at the top of the category or add a latest products to it.

avd
Newbie

Posts

Joined
Tue Jan 12, 2010 11:35 pm

Post by Xsecrets » Sat Jan 16, 2010 3:13 am

that last bit of code in simple terms is a list of ways to sort that can be used in the dropdown.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by avd » Sat Jan 16, 2010 7:51 pm

Is p.date_added meant to show in the dropdown list? i think i might just get rid of the sort by text and dropdown, do you know how i can do this?

Thanks

avd
Newbie

Posts

Joined
Tue Jan 12, 2010 11:35 pm

Post by Xsecrets » Sat Jan 16, 2010 11:29 pm

no nothing I did will show up in the dropdown. It simply puts everything in place so you could add options to the dropdown that use the new fields.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by avd » Mon Jan 18, 2010 2:59 am

Hi,

Do you know how to remove the sort by text and dropdown?

Thanks

avd
Newbie

Posts

Joined
Tue Jan 12, 2010 11:35 pm

Post by Xsecrets » Mon Jan 18, 2010 3:05 am

It should be fairly easy to find in the category.tpl off the top of my head I think you should be able to simply remove it from there without complications, but no guarantees.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by ameliaa » Mon Feb 01, 2010 9:21 am

Xsecrets wrote:ah ok I see it now.

in catalog/controller/product/category.php
around line 64 change

Code: Select all

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

Code: Select all

if (isset($this->request->get['sort'])) {
				$sort = $this->request->get['sort'];
			} else {
				$sort = 'p.date_added';
			}
and in /catalog/model/catalog/product.php
around line 18 change

Code: Select all

		$sort_data = array(
			'pd.name',
			'p.price',
			'rating'
		);
to

Code: Select all

		$sort_data = array(
			'pd.name',
			'p.price',
			'rating',
         'p.date_added'
		);

Will this work for version 1.4? I want my products to be sorted by date too by default. Hope to hear from you.

New member

Posts

Joined
Fri Jan 29, 2010 6:31 pm

Post by webstudent1 » Sat Apr 10, 2010 4:04 am

Working :).

in /catalog/model/catalog/product.php
change all
$sort_data = array(
'pd.name',
'p.price',
'rating',

TO

$sort_data = array(
'pd.name',
'p.price',
'rating',
'p.date_added'

in the query above make sure you add it also. egample.

$sql = "SELECT *, pd.name AS name, p.image, p.date_added, m.name AS manufacturer,

now you can edit .php controllers for each as needed
eg catalog/contoller/product/catagory.php

Cya

New member

Posts

Joined
Thu Jan 07, 2010 2:24 am

Post by jerome » Fri Jul 23, 2010 6:36 am

how can i do "Sorting products in category by latest" with 1.4.8

Newbie

Posts

Joined
Fri Jul 23, 2010 6:27 am

Post by developer » Tue Aug 24, 2010 10:56 pm

How can I sort products by model?

User avatar
New member

Posts

Joined
Tue Jul 27, 2010 8:06 pm

Post by dramony » Sat Aug 28, 2010 12:38 pm

jerome wrote:how can i do "Sorting products in category by latest" with 1.4.8
Will this work on 1.4.8b?

User avatar
Active Member

Posts

Joined
Sat Oct 24, 2009 12:34 pm
Who is online

Users browsing this forum: No registered users and 56 guests