Post by Impaler » Thu Jan 20, 2022 10:42 pm

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 :)

New member

Posts

Joined
Fri Aug 24, 2012 3:11 am

Post by thekrotek » Thu Jan 20, 2022 11:02 pm

Open catalog/model/catalog/product.php and add a check for category ID to getProducts() function.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by paulfeakins » Fri Jan 21, 2022 7:32 pm

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.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by Impaler » Fri Jan 21, 2022 7:39 pm

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 :)

New member

Posts

Joined
Fri Aug 24, 2012 3:11 am

Post by by mona » Fri Jan 21, 2022 11:02 pm

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';
		}

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by ssm971 » Tue Feb 08, 2022 7:19 am

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.

Newbie

Posts

Joined
Sun Dec 12, 2021 5:43 am
Who is online

Users browsing this forum: sidclel and 86 guests