Post by lukehackett85 » Sat Dec 19, 2020 12:07 am

Hi guys,

I am using OpenCart 3.0.3.2

I have a main menu, part of which displays links to categories (a count of 10 categories) from within a larger category (contains about 50 categories) and what it shows is the first 10 alphabetically.

I would prefer it to display the most recently added 10, in order

Is it possible to adjust this? I've looked all over but can't seem to find an option for it.

Best regards

Luke

New member

Posts

Joined
Sun Apr 24, 2016 5:09 am

Post by IP_CAM » Sat Dec 19, 2020 3:15 am

checked here already on what exists ?
https://www.opencart.com/index.php?rout ... earch=menu

I am no longer active at the Forum. Please do NOT send me Personal Mails,
they will no longer be replied to.
My Github OC Site: https://github.com/IP-CAM
4'100 + FREE OC Extensions, on the World's largest Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by grgr » Sat Dec 19, 2020 3:22 pm

In ../catalog/controller/common/menu.php
Change this line:

Code: Select all

$children = $this->model_catalog_category->getCategories($category['category_id']);
To this:

Code: Select all

$children = $this->model_catalog_category->getCategoriesDateSorted($category['category_id']);
Then in ../catalog/model/catalog/category.php
Add a new function that sorts by date:

Code: Select all

	public function getCategoriesDateSorted($parent_id = 0) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.parent_id = '" . (int)$parent_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "'  AND c.status = '1' ORDER BY c.date_added, LCASE(cd.name)");

		return $query->rows;
	}
Untested and don't know what else that will effect though, if anything.

-
Image Image Image Image
VIEW ALL EXTENSIONS * EXTENSION SUPPORT * WEBSITE * CUSTOM REQUESTS


User avatar
Active Member

Posts

Joined
Mon Mar 28, 2011 4:08 pm
Location - UK
Who is online

Users browsing this forum: No registered users and 33 guests