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
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";
}
Code: Select all
if (in_array($sort, $sort_data)) {
$sql .= " ORDER BY " . $sort;
} else {
$sql .= " ORDER BY p.date_added, pd.name";
}
around line 70 change
Code: Select all
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
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
so what is it sorted by? that change should sort it by the date_added field from the database, which should = latest products.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.
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
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';
}
Code: Select all
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.date_added';
}
around line 18 change
Code: Select all
$sort_data = array(
'pd.name',
'p.price',
'rating'
);
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
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.
OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter
OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter
OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter
Xsecrets wrote:ah ok I see it now.
in catalog/controller/product/category.php
around line 64 changetoCode: Select all
if (isset($this->request->get['sort'])) { $sort = $this->request->get['sort']; } else { $sort = 'pd.name'; }
and in /catalog/model/catalog/product.phpCode: Select all
if (isset($this->request->get['sort'])) { $sort = $this->request->get['sort']; } else { $sort = 'p.date_added'; }
around line 18 changetoCode: Select all
$sort_data = array( 'pd.name', 'p.price', 'rating' );
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.

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
Users browsing this forum: Amazon [Bot], Google [Bot] and 64 guests