Ewetoye, Ibrahim
Mathsend Blog

Mathsend Blog

How to Change Default Sorting of Odoo Shop Catalog

Setting the default sorting order for the catalog of products in the shop

How to Change Default Sorting of Odoo Shop Catalog
Ewetoye, Ibrahim's photo
Ewetoye, Ibrahim

Published on Jul 19, 2021

2 min read

Sooner or later, users of Odoo ERP system for website shopping may need to have a preffered default sorting order for the website product catalog.

Default sorting pattern

By default products seem to be randomly arranged; but in its real sense, the default is that products are sorted in an order that reads published>>sequence>>name. In other words:

  • All product are first grouped into two fractions, the published ones comes first while the unpublished ones are pushed to the end and only shown to internal users.
  • Within each fraction, products with lower sequence value comes first followed by higher ones in ascending order
  • Products with the same sequence are alphabetically arranged.

Set the default sorting pattern

From the foregoing, the easiest way may be to make sure the sequence is in the desired order. If the sequence can't be ascertained to be in the desired order then read on.

Disclaimer: This post is just to show how the aforestated feature can be achieved and I will be editing the actual Odoo file; generally, it is always considered a good practice not to modify an Odoo file but through a custom module.

That said, choose your ooperating system:
Linux
Windows

  1. Launch your terminal
  2. cd to your Odoo installation directory
  3. just to make sure you have the write access, do sudo su
  4. with your preferred editor, in my own case I will be using vim, open the main.py file in the location addons/website_sale/controllers/main.py Thus, I will do vi addons/website_sale/controllers/main.py
  5. search for url = shop: in vi /url = shop
    Hit Enter, then i to change the mode to INSERT

  6. After the Matching line Sort as needed, for alphabetically ascending order do:

    if "order" not in post:
     post["order"]="name asc"
    
  7. Save and exit. Press Esc to change the mode Type :wq to save and exit in vim

  8. Restart the server: /etc/init.d/odoo restart

Done


  1. Open any text editor
  2. open the odoo installation directory and locate server\odoo\addons\website_sale\controllers\main.py.
    In my case, the path is C:\Program Files (x86)\Odoo 12.0\server\odoo\addons\website_sale\controllers\main.py
  3. search for url = shop
  4. After the Matching line Sort as needed, for alphabetically ascending order do:
    if "order" not in post:
     post["order"]="name asc"
    
  5. Save and exit.

  6. Restart the server:

    • Go to services
    • Search for the odoo server, mine is odoo-server-12.0
    • Select an click restart in the left pane

Done

 
Share this