Opencart extensions free download · 7 min read · Updated

More Sort Options for OpenCart 4 and 3: Sort by Best Sellers, Newest and Most Reviewed (Free Extension)

A free extension that adds Best Sellers, Newest and Most Reviewed sort orders to OpenCart 4 and 3 category, search and brand pages.

Opencart more sort options

Open any category in a default OpenCart store and look at the Sort By list: Default, Name, Price, Rating and Model. Two of the sort orders shoppers expect most are missing. There’s no way to see what sells best, and no way to see what’s new.

More Sort Options is a free extension that adds Best Sellers, Newest and Most Reviewed to that list on category, search and brand pages. You can also make one of them the default, so a category opens with your best sellers first. We built it for OpenCart 4.1.0.4 and OpenCart 3.0.5.1, and the sorting happens in the database, so it stays correct on page 2, page 3 and beyond.

Download More Sort Options

OpenCart 4 category page Sort By dropdown open, listing Default, Best Sellers, Newest, Most Reviewed, then Name, Price, Rating and Model options
The three new choices sit right after Default in the Sort By list.

The three new sort orders

  • Best Sellers: units sold, counted from orders with a Processing or Complete order status. Those are the statuses you set in System > Settings > Option, so pending, canceled and refunded orders don’t count. You can limit it to the last N days so last year’s hit doesn’t stay on top forever.
  • Newest: the date the product was added, newest first. OpenCart already supports this sort internally. It just never shows it in the list.
  • Most Reviewed: the number of approved reviews. Unapproved reviews don’t count.

Each one can be switched on or off, and products with the same score fall back to alphabetical order, so the list never looks random.

Install in OpenCart 4

  1. Go to Extensions > Installer, upload moresort.ocmod.zip and click the green +.
  2. Go to Extensions > Extensions, choose Modules, and install More Sort Options.
  3. Click the pencil, turn Status on, pick the sort orders you want and save.

Install in OpenCart 3

  1. Go to Extensions > Installer and upload moresort.ocmod.zip. No modification refresh is needed.
  2. Go to Extensions > Extensions, choose Modules, and install More Sort Options.
  3. Edit it, set Status to Enabled, choose the sort orders and click Save.

Settings

More Sort Options settings in OpenCart 4 with switches for Status, Best Sellers, Newest and Most Reviewed, a Count sales from the last field set to 0 days, and a Default sort order dropdown
The settings page in OpenCart 4.
  • Best Sellers, Newest, Most Reviewed: show or hide each choice.
  • Count sales from the last: days. 0 means all time. A window like 90 days keeps Best Sellers current.
  • Default sort order: what a shopper sees when they open a category, search or brand page without picking a sort. Leave it on “OpenCart default (sort order, then name)” to keep the normal behavior, or choose Best Sellers to lead with your proven products.

What we saw when testing

We added a few demo orders on the test store and compared the Laptops category with each sort order:

Sort ByOrder on the page
DefaultHP LP3065, MacBook, MacBook Air, MacBook Pro, Sony VAIO
Best SellersMacBook Air, Sony VAIO, MacBook Pro, MacBook, HP LP3065
NewestHP LP3065, Sony VAIO, MacBook Pro, MacBook Air, MacBook
OpenCart 4 Laptops category sorted by Best Sellers showing MacBook Air, Sony VAIO and MacBook Pro first
Laptops sorted by Best Sellers on OpenCart 4.1.0.4.

We also checked the places where sort orders usually break:

  • Paging: with 2 products per page, page 2 continued the Best Sellers order. The sort runs in SQL, not on the 10 products that happen to be on the page.
  • Search and brand pages: a search for “mac” sorted by Best Sellers returned MacBook Air, MacBook, MacBook Pro, iMac, and the Apple brand page worked the same way.
  • The days window: changing it from all time to 90 days changed the order right away, because old orders dropped out.
  • Other sort extensions: with our Out-of-Stock Products Last extension also on, sold-out items still moved to the end and the rest stayed in Best Sellers order.

How it works

This one was harder than it sounds. OpenCart’s getProducts() only accepts sort values from a fixed list, and there’s no event that can change its ORDER BY. Sorting in PHP after the query isn’t an option either, because it would only reorder the current page.

So the extension wraps OpenCart’s database object for the one request where it’s needed. A startup action checks the route and the chosen sort, builds the SQL expression for it, and swaps the wrapped objects into the registry:

if ($sort == 'sales' && $this->config->get('module_moresort_sales')) {
    $statuses = array_map('intval', array_merge((array)$this->config->get('config_processing_status'), (array)$this->config->get('config_complete_status')));
    $days = (int)$this->config->get('module_moresort_days');

    // Units sold in orders that reached a processing or complete status.
    $expression = "(SELECT COALESCE(SUM(`op`.`quantity`), 0) FROM `" . DB_PREFIX . "order_product` `op` INNER JOIN `" . DB_PREFIX . "order` `o` ON (`o`.`order_id` = `op`.`order_id`) WHERE `op`.`product_id` = `p`.`product_id` AND `o`.`order_status_id` IN (" . implode(',', $statuses ?: [0]) . ")" . ($days > 0 ? " AND `o`.`date_added` >= DATE_SUB(NOW(), INTERVAL " . $days . " DAY)" : "") . ")";
} elseif ($sort == 'reviews' && $this->config->get('module_moresort_reviews')) {
    // Approved reviews only.
    $expression = "(SELECT COUNT(*) FROM `" . DB_PREFIX . "review` `r2` WHERE `r2`.`product_id` = `p`.`product_id` AND `r2`.`status` = '1')";
} else {
    // Newest uses OpenCart's own p.date_added sort, so nothing to change here.
    return;
}

require_once DIR_EXTENSION . 'moresort/system/library/moresort.php';

$this->registry->set('db', new \Opencart\Extension\Moresort\System\Library\Db($this->registry->get('db'), $expression));
$this->registry->set('cache', new \Opencart\Extension\Moresort\System\Library\Cache($this->registry->get('cache'), $expression));

The wrapper only touches the product list query and only replaces its fallback sort. Every other query passes through unchanged:

public function rewrite(string $sql): string {
    // getProducts() falls back to "ORDER BY p.sort_order" for sort values it doesn't know.
    // The ORDER BY keyword is not part of the pattern, so other extensions may add sort keys in front.
    if (str_starts_with($sql, 'SELECT DISTINCT *, `pd`.`name`, `p`.`image`,')) {
        return preg_replace('/`p`\.`sort_order` (ASC|DESC), LCASE\(`pd`\.`name`\) (ASC|DESC)( LIMIT |$)/', $this->expression . ' DESC, LCASE(`pd`.`name`) ASC$3', $sql, 1);
    }

    return $sql;
}

One thing we found while testing the OpenCart 4 build: getProducts() caches its results for an hour under an md5 of the SQL. An unknown sort value produces the same SQL as the default sort, so without help, Best Sellers would show the cached default list. The extension also wraps the cache and gives product lists their own cache keys while a new sort is active. The key includes a hash of the sort expression, so changing the days setting doesn’t serve an old list. Keys still start with product., so OpenCart clears them whenever you edit a product.

The new options are added to the dropdown with view events on the category, search and brand templates. They’re built from the Default link, so filters, the page limit and the search words carry over.

What’s different in the OpenCart 3 build

OpenCart 3.0.5.1 category page with the Sort By dropdown set to Best Sellers
Best Sellers on OpenCart 3.0.5.1.
  • OpenCart 3 has no startup actions, so the database wrapper is installed by catalog/controller/product/category/before, product/search/before and product/manufacturer/info/before events, which run before the page loads its products.
  • OpenCart 3’s getProducts() doesn’t cache its results, so no cache wrapper is needed.
  • The settings and the three sort orders are the same.
$this->model_setting_event->addEvent('moresort', 'catalog/controller/product/category/before', 'extension/event/moresort/startup');
$this->model_setting_event->addEvent('moresort', 'catalog/controller/product/search/before', 'extension/event/moresort/startup');
$this->model_setting_event->addEvent('moresort', 'catalog/controller/product/manufacturer/info/before', 'extension/event/moresort/startup');

// Add the choices to the Sort By list.
$this->model_setting_event->addEvent('moresort', 'catalog/view/product/category/before', 'extension/event/moresort/sorts');
$this->model_setting_event->addEvent('moresort', 'catalog/view/product/search/before', 'extension/event/moresort/sorts');
$this->model_setting_event->addEvent('moresort', 'catalog/view/product/manufacturer_info/before', 'extension/event/moresort/sorts');

Things to know

  • Best Sellers needs orders. On a new store, every product scores 0 and the list falls back to name order.
  • Large catalogs: the Best Sellers sort counts sales with a subquery per product. On the demo store it was instant. On stores with hundreds of thousands of order lines, use the days window to keep it fast.
  • Product modules aren’t affected. Featured, Latest and Bestseller modules keep working as before. Only category, search and brand listings get the new options.

Please let us know if you have any questions or suggestions, and subscribe to our YouTube channel for more OpenCart video tutorials. You can also find us on Twitter and Facebook.

Rupak Nepali
Written byRupak Nepali

Rupak Nepali is a web developer, manage Webocreation website and the author of six books:
Getting Started with OpenCart Module Development (Packt, 2013),
OpenCart Theme and Module Development (Packt, 2015),
OpenCart 4: Dev Guide for Themes & Extensions (2024),
OpenCart 4: User Manual (2025),
Cloudflare for the Enterprise Website (2026) and
The Technical Web Guide for Marketers (2026).
Rupak has built OpenCart stores and extensions since 2010, has published more than 600 tutorials on Webocreation, and shares free OpenCart extensions on GitHub.
Find Rupak on
GitHub | Amazon | LinkedIn | X | YouTube.

Leave a Reply

Your email address will not be published. Required fields are marked *