Page 1 of 1
Sort products by DATE ADDED in a SINGLE CATEGORY?
Posted: Thu Jan 20, 2022 10:42 pm
by Impaler
Hello everybody,
I wonder can anyone help me with a hack where I could make one particular category to use default sorting by PRODUCT DATE ADDED instead of default ordering. This only needs to happen for one category. I don't mind any hard-coding. I don't care about the means I just want a result.
Can anybody help me please
Re: Sort products by DATE ADDED in a SINGLE CATEGORY?
Posted: Thu Jan 20, 2022 11:02 pm
by thekrotek
Open catalog/model/catalog/product.php and add a check for category ID to getProducts() function.
Re: Sort products by DATE ADDED in a SINGLE CATEGORY?
Posted: Fri Jan 21, 2022 7:32 pm
by paulfeakins
Impaler wrote: ↑Thu Jan 20, 2022 10:42 pm
I don't mind any hard-coding. I don't care about the means I just want a result.
This is how sites turn to junk and then you have to pay more for a decent developer to fix them in future.
Re: Sort products by DATE ADDED in a SINGLE CATEGORY?
Posted: Fri Jan 21, 2022 7:39 pm
by Impaler
I said I don't mind hard coding because I don't want to overbear anyone who can help me. I'd make a ocmod for the code myself
Re: Sort products by DATE ADDED in a SINGLE CATEGORY?
Posted: Fri Jan 21, 2022 11:02 pm
by by mona
in your category controller this code sets the sort field and order if given, otherwise it sets the defaults.
Code: Select all
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
You can check for any given category id (12 in example) and set the default to your liking:
Code: Select all
$parts = explode('_', (string)$this->request->get['path']);
$category_id = (int)array_pop($parts);
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} elseif ($category_id == 12) {
$sort = 'p.date_added';
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} elseif ($category_id == 12) {
$order = 'ASC';
} else {
$order = 'ASC';
}
Re: Sort products by DATE ADDED in a SINGLE CATEGORY?
Posted: Tue Feb 08, 2022 7:19 am
by ssm971
I changed the presentation of my standard general department with to product modification date with an XML, every time I change the date in the product registration it becomes the first in the category.