Post by guldan » Tue Apr 22, 2014 6:33 pm

Hello friends,

I'm using Opencart 1.5.4, clean install.
I have a category that I named "New Arrivals". The products in this category should be automatically sorted so that the newest products will be shown first.
After searching the forum, basically what I've found is to modify 2 lines on the controller/category.php like this:

change $sort = 'p.sort_order'; to $sort = 'p.date_added';
and change $order = 'ASC'; to $order = 'DESC';

Yes, it works BUT it affects ALL category pages!
Now all products in each category are sorted by default newest first.
Whereas, what I want is to apply it in "New Arrivals" category ONLY.

What I have in my mind, applying this to specific category will have something to do with category id (path).
My "New Arrivals" category id is 102. So I must first detect the current path. If it is 102 then apply sort by newest. If it is not 102, then ignore.
Then I tried to modify controller/category.php like this

Part 1, find this:

Code: Select all

$sort = 'p.sort_order';
Change to:

Code: Select all

if ($this->request->get['path'] == '102')
{
$sort = 'p.date_added';
}
$sort = 'p.sort_order';
Part 2, find this:

Code: Select all

$order = 'ASC';
Change to:

Code: Select all

if ($this->request->get['path'] == '102')
{
$order = 'DESC';
}
$order = 'ASC';
But it doesn't work. I'm not sure if the controller/category.php is the right file to modify.
Or it might be wrong lines (and wrong syntax)?

Please help me :)
Thank you..

Newbie

Posts

Joined
Sat Apr 06, 2013 5:06 pm

Post by Axansh » Wed Apr 23, 2014 2:08 am

Small error in writing a code.

You should write like this :

if(condition){
---code--
}else{
--code--
}

if you write without else,everytime it overwrite previous condition.

Cheer!

Thanks and Best Regards,
Axansh Sheth

Our Opencart Module
All in ONE SEO |
Multi-purpose pop |
Restaurant theme |
Store time save module


User avatar
Active Member

Posts

Joined
Mon Feb 06, 2012 3:07 pm

Post by guldan » Wed Apr 23, 2014 12:46 pm

Axansh, thank you!!!!!
After adding "else" and its brackets, the code works!
Now the products are sorted newest-first ONLY on the intended category. The others categories are not affected.

Wow, what a shame. It turns out that I haven't yet graduated from that "if-else" basic lesson :))))

Newbie

Posts

Joined
Sat Apr 06, 2013 5:06 pm
Who is online

Users browsing this forum: No registered users and 76 guests