Page 1 of 1
Sort Products in Category by Date Available
Posted: Fri Mar 16, 2012 9:57 am
by danswano
Hello,
How to Sort Products in Category by Date Available?
tried to modify category.php to:
Code: Select all
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.date_available';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'DESC';
}
but it didn't work for me, what to do?
Using OC 1.5.1.3
Re: Sort Products in Category by Date Available
Posted: Wed Mar 21, 2012 3:18 am
by uksitebuilder
clear you system/cache folder (apart from index.html)
Re: Sort Products in Category by Date Available
Posted: Wed Mar 21, 2012 3:23 am
by danswano
You mean my method works?
Re: Sort Products in Category by Date Available
Posted: Wed Mar 21, 2012 3:57 am
by uksitebuilder
It should do
date_available is a column in the product table so it should be passed to the SQL in the model file
Re: Sort Products in Category by Date Available
Posted: Wed Mar 21, 2012 6:56 am
by danswano
I don't think this method works, it's randomizing the product i don't know based on what, cleared the cache although, i think the db query is missing that will call the date.
Can you look at the code please?

Re: Sort Products in Category by Date Available
Posted: Wed Mar 21, 2012 5:07 pm
by GoGo OpenCart
Try "playing" with the:
.../catalog/model/catalog/product.php
Re: Sort Products in Category by Date Available
Posted: Wed Mar 21, 2012 9:25 pm
by danswano
Can you please be more specific?

Re: Sort Products in Category by Date Available
Posted: Fri Mar 23, 2012 11:17 am
by mondokat
the value is actually "date_added" not "date_available". Also, I assume you'd like the newly added stuff to be on top. So we need to change the sort order. The code looks like this:
Code: Select all
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.date_added';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'DESC';
}
Re: Sort Products in Category by Date Available
Posted: Fri Mar 23, 2012 11:29 am
by mondokat
oh, if you DO want date available, you can add it in the model file mentioned above:
Code: Select all
$sort_data = array(
'pd.name',
'p.model',
'p.quantity',
'p.price',
'rating',
'p.sort_order',
'p.date_added',
'p.date_available'
);
Re: Sort Products in Category by Date Available
Posted: Fri Mar 23, 2012 7:15 pm
by danswano
@mondokat
it didn't work.
Re: Sort Products in Category by Date Available
Posted: Fri Mar 23, 2012 7:32 pm
by inspirio
Re: Sort Products in Category by Date Available
Posted: Fri Mar 23, 2012 7:37 pm
by danswano
What model dude? i want date available not model.
Re: Sort Products in Category by Date Available
Posted: Mon May 07, 2012 9:58 am
by newuserint
danswano wrote:What model dude? i want date available not model.
He means the model file which creates the model for the template.
By the way tell me if any of this works, i also want this.
Re: Sort Products in Category by Date Available
Posted: Wed Sep 26, 2012 3:04 pm
by owner
mondokat wrote:oh, if you DO want date available, you can add it in the model file mentioned above:
Code: Select all
$sort_data = array(
'pd.name',
'p.model',
'p.quantity',
'p.price',
'rating',
'p.sort_order',
'p.date_added',
'p.date_available'
);
There's no sort of product_id??
i'm trying to search the forum, but didn't find any
try p.date_added, but since i imported from another ecommerce engine, all products has same date/time..
so i need the sort by product_id..
anyone can help with this simple things?

thanks