diff --git a/website_sale_category_show_empty/README.rst b/website_sale_category_show_empty/README.rst new file mode 100644 index 0000000000..8ec429a356 --- /dev/null +++ b/website_sale_category_show_empty/README.rst @@ -0,0 +1,110 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +================================ +Website Sale Category Show Empty +================================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f06a259291b5fb6e1ffe983548192e4a25b76ddace6a53dfe8bb44cba4bf959d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github + :target: https://github.com/OCA/e-commerce/tree/19.0/website_sale_category_show_empty + :alt: OCA/e-commerce +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/e-commerce-19-0/e-commerce-19-0-website_sale_category_show_empty + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Odoo hides eCommerce category pages that hold no published product from +public and portal visitors. The record rule +``website_sale.empty_public_categories_rule`` restricts them to +categories where ``has_published_products`` is true, and because the +``/shop/category`` route turns the resulting access error into a 404, +visitors get a "page not found" instead of the category page. + +That is the wanted behaviour for a catalogue that mirrors stock, but not +for pages that carry editorial content of their own -- a manufacturer or +brand page, for instance, which a shop may want to keep reachable even +while nothing of that brand is published. + +This module adds a *Show When Empty* flag on the category. Flagged +categories stay readable for public and portal visitors whatever their +product count. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Go to *Website > eCommerce > Products > eCommerce Categories*. +2. Open a category and tick *Show When Empty*. + +The category page is now reachable for visitors even with no published +product, and renders as an empty category. + +Note that the flag governs access to the page only. Shop sidebars and +mega menus filter on ``has_published_products`` directly rather than +through the record rule, so a flagged empty category is reachable by its +URL but is still left out of those navigation blocks. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ForgeFlow + +Contributors +------------ + +- `ForgeFlow `__: + + - Marc Gimeno + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/e-commerce `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_category_show_empty/__init__.py b/website_sale_category_show_empty/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/website_sale_category_show_empty/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/website_sale_category_show_empty/__manifest__.py b/website_sale_category_show_empty/__manifest__.py new file mode 100644 index 0000000000..80a3e6711e --- /dev/null +++ b/website_sale_category_show_empty/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Website Sale Category Show Empty", + "summary": "Let public and portal visitors open eCommerce category pages" + " that have no published products", + "version": "19.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/e-commerce", + "license": "AGPL-3", + "category": "Website", + "depends": ["website_sale"], + "data": [ + "security/product_public_category_security.xml", + "views/product_public_category_views.xml", + ], + "installable": True, +} diff --git a/website_sale_category_show_empty/models/__init__.py b/website_sale_category_show_empty/models/__init__.py new file mode 100644 index 0000000000..0a91ef28d4 --- /dev/null +++ b/website_sale_category_show_empty/models/__init__.py @@ -0,0 +1 @@ +from . import product_public_category diff --git a/website_sale_category_show_empty/models/product_public_category.py b/website_sale_category_show_empty/models/product_public_category.py new file mode 100644 index 0000000000..5179500151 --- /dev/null +++ b/website_sale_category_show_empty/models/product_public_category.py @@ -0,0 +1,14 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ProductPublicCategory(models.Model): + _inherit = "product.public.category" + + show_when_empty = fields.Boolean( + help="Let public and portal visitors open this category's page even " + "when neither the category nor its children hold a published " + "product. Without this, the page answers 404.", + ) diff --git a/website_sale_category_show_empty/pyproject.toml b/website_sale_category_show_empty/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_sale_category_show_empty/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_sale_category_show_empty/readme/CONTRIBUTORS.md b/website_sale_category_show_empty/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..cfabcc6884 --- /dev/null +++ b/website_sale_category_show_empty/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [ForgeFlow](https://www.forgeflow.com): + - Marc Gimeno diff --git a/website_sale_category_show_empty/readme/DESCRIPTION.md b/website_sale_category_show_empty/readme/DESCRIPTION.md new file mode 100644 index 0000000000..a0e2c93f3c --- /dev/null +++ b/website_sale_category_show_empty/readme/DESCRIPTION.md @@ -0,0 +1,15 @@ +Odoo hides eCommerce category pages that hold no published product from +public and portal visitors. The record rule +`website_sale.empty_public_categories_rule` restricts them to categories +where `has_published_products` is true, and because the `/shop/category` +route turns the resulting access error into a 404, visitors get a "page +not found" instead of the category page. + +That is the wanted behaviour for a catalogue that mirrors stock, but not +for pages that carry editorial content of their own -- a manufacturer or +brand page, for instance, which a shop may want to keep reachable even +while nothing of that brand is published. + +This module adds a *Show When Empty* flag on the category. Flagged +categories stay readable for public and portal visitors whatever their +product count. diff --git a/website_sale_category_show_empty/readme/USAGE.md b/website_sale_category_show_empty/readme/USAGE.md new file mode 100644 index 0000000000..bfb834471a --- /dev/null +++ b/website_sale_category_show_empty/readme/USAGE.md @@ -0,0 +1,10 @@ +1. Go to *Website \> eCommerce \> Products \> eCommerce Categories*. +2. Open a category and tick *Show When Empty*. + +The category page is now reachable for visitors even with no published +product, and renders as an empty category. + +Note that the flag governs access to the page only. Shop sidebars and +mega menus filter on `has_published_products` directly rather than +through the record rule, so a flagged empty category is reachable by its +URL but is still left out of those navigation blocks. diff --git a/website_sale_category_show_empty/security/product_public_category_security.xml b/website_sale_category_show_empty/security/product_public_category_security.xml new file mode 100644 index 0000000000..2679d72554 --- /dev/null +++ b/website_sale_category_show_empty/security/product_public_category_security.xml @@ -0,0 +1,28 @@ + + + + + Show flagged empty eCommerce categories to public/portal users + + [('show_when_empty', '=', True)] + + + + + + + diff --git a/website_sale_category_show_empty/static/description/index.html b/website_sale_category_show_empty/static/description/index.html new file mode 100644 index 0000000000..91039ab4bd --- /dev/null +++ b/website_sale_category_show_empty/static/description/index.html @@ -0,0 +1,458 @@ + + + + + +Website Sale Category Show Empty + + + +
+ + + +Odoo Community Association + +
+

Website Sale Category Show Empty

+ +

Beta License: AGPL-3 OCA/e-commerce Translate me on Weblate Try me on Runboat

+

Odoo hides eCommerce category pages that hold no published product from +public and portal visitors. The record rule +website_sale.empty_public_categories_rule restricts them to +categories where has_published_products is true, and because the +/shop/category route turns the resulting access error into a 404, +visitors get a “page not found” instead of the category page.

+

That is the wanted behaviour for a catalogue that mirrors stock, but not +for pages that carry editorial content of their own – a manufacturer or +brand page, for instance, which a shop may want to keep reachable even +while nothing of that brand is published.

+

This module adds a Show When Empty flag on the category. Flagged +categories stay readable for public and portal visitors whatever their +product count.

+

Table of contents

+ +
+

Usage

+
    +
  1. Go to Website > eCommerce > Products > eCommerce Categories.
  2. +
  3. Open a category and tick Show When Empty.
  4. +
+

The category page is now reachable for visitors even with no published +product, and renders as an empty category.

+

Note that the flag governs access to the page only. Shop sidebars and +mega menus filter on has_published_products directly rather than +through the record rule, so a flagged empty category is reachable by its +URL but is still left out of those navigation blocks.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/e-commerce project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/website_sale_category_show_empty/tests/__init__.py b/website_sale_category_show_empty/tests/__init__.py new file mode 100644 index 0000000000..6c4dca74ba --- /dev/null +++ b/website_sale_category_show_empty/tests/__init__.py @@ -0,0 +1 @@ +from . import test_website_sale_category_show_empty diff --git a/website_sale_category_show_empty/tests/test_website_sale_category_show_empty.py b/website_sale_category_show_empty/tests/test_website_sale_category_show_empty.py new file mode 100644 index 0000000000..da33ffddb4 --- /dev/null +++ b/website_sale_category_show_empty/tests/test_website_sale_category_show_empty.py @@ -0,0 +1,49 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.exceptions import AccessError +from odoo.tests import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestWebsiteSaleCategoryShowEmpty(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.public_user = cls.env.ref("base.public_user") + cls.category = cls.env["product.public.category"].create( + {"name": "Empty category"} + ) + cls.child = cls.env["product.public.category"].create( + {"name": "Empty child category", "parent_id": cls.category.id} + ) + + def _read_as_public(self, category): + category.with_user(self.public_user).check_access("read") + + def test_01_empty_category_is_hidden(self): + """Without the flag, the core rule keeps the category unreadable.""" + with self.assertRaises(AccessError): + self._read_as_public(self.category) + + def test_02_flag_makes_category_readable(self): + self.category.show_when_empty = True + self._read_as_public(self.category) + + def test_03_flag_does_not_leak_to_siblings(self): + """The flag widens access for its own record only.""" + self.category.show_when_empty = True + with self.assertRaises(AccessError): + self._read_as_public(self.child) + + def test_04_category_with_published_product_stays_readable(self): + """The core rule keeps working for categories that do hold products.""" + self.env["product.template"].create( + { + "name": "Published product", + "is_published": True, + "public_categ_ids": [(6, 0, self.child.ids)], + } + ) + self._read_as_public(self.child) + self._read_as_public(self.category) diff --git a/website_sale_category_show_empty/views/product_public_category_views.xml b/website_sale_category_show_empty/views/product_public_category_views.xml new file mode 100644 index 0000000000..7b0e8a126c --- /dev/null +++ b/website_sale_category_show_empty/views/product_public_category_views.xml @@ -0,0 +1,24 @@ + + + + product.public.category.form.show.empty + product.public.category + + + + + + + + + + product.public.category.list.show.empty + product.public.category + + + + + + + +