addons-cm/website_sale_disable_cart
GitHub Copilot fbd43bb459
Some checks failed
CI / lint (pull_request) Successful in 33s
CI / test (pull_request) Failing after 9m29s
CI / review (pull_request) Has been skipped
[REF] all: pass pre-commit on the whole repo
Needed for the lint job of the CI to go green. Mostly automatic hook
fixes (black, isort, prettier, pyupgrade, autoflake, whitespace). By hand:

- flake8: two unused imports, an ambiguous variable name `l`.
- pylint-odoo mandatory: manifest keys equal to their default value
  (installable, application, data, external_dependencies).
- end-of-file-fixer skips *.patch too, like trailing-whitespace: the
  upstream patches stay as git format-patch wrote them.

No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 14:34:58 +02:00
..
controllers [ADD] website_sale_disable_cart: extract cart restriction from website_sale_aplicoop 2026-08-06 11:34:59 +02:00
i18n [ADD] website_sale_disable_cart: extract cart restriction from website_sale_aplicoop 2026-08-06 11:34:59 +02:00
models [ADD] website_sale_disable_cart: extract cart restriction from website_sale_aplicoop 2026-08-06 11:34:59 +02:00
readme [ADD] website_sale_disable_cart: extract cart restriction from website_sale_aplicoop 2026-08-06 11:34:59 +02:00
tests [ADD] website_sale_disable_cart: extract cart restriction from website_sale_aplicoop 2026-08-06 11:34:59 +02:00
views [ADD] website_sale_disable_cart: extract cart restriction from website_sale_aplicoop 2026-08-06 11:34:59 +02:00
__init__.py [ADD] website_sale_disable_cart: extract cart restriction from website_sale_aplicoop 2026-08-06 11:34:59 +02:00
__manifest__.py [REF] all: pass pre-commit on the whole repo 2026-10-04 14:34:58 +02:00
LICENSE.txt [ADD] website_sale_disable_cart: extract cart restriction from website_sale_aplicoop 2026-08-06 11:34:59 +02:00
README.rst [ADD] website_sale_disable_cart: extract cart restriction from website_sale_aplicoop 2026-08-06 11:34:59 +02:00

===============================
Website Sale - Disable Cart
===============================

.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg
   :target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
   :alt: License: AGPL-3
.. image:: https://img.shields.io/badge/Odoo-18.0-blue
   :alt: Odoo: 18.0

Turn the standard Odoo eCommerce shop into a **read-only product catalog**:
visitors can browse, search and open product pages, but the standard
``website_sale`` shopping cart is not reachable any more.

It is meant for sites where the actual ordering happens somewhere else — for
example the group order flow of ``website_sale_aplicoop`` (``/eskaera``), a
quotation request form, or an offline/phone process — while the public shop is
still useful as a catalog.

What the module does
====================

- Hides the cart link and badge from all 12 standard website header styles
  (default, mobile, hamburger, stretch, vertical, search, boxed, sidebar and
  sales one to four).
- Removes the "Add to cart" quick-add area from the product listing cards.
- Neutralizes the standard cart endpoints:

  - ``/shop/cart`` and ``/shop/cart/update`` redirect to a configurable URL.
  - ``/shop/cart/update_json`` returns an empty payload (no cart is written).
  - ``/shop/cart/quantity`` always returns ``0``.
  - ``/shop/cart/clear`` does nothing.

Only the **cart** is disabled. Product listing, search, product pages and the
rest of ``website_sale`` are untouched. Checkout and payment routes are left
untouched too; with an empty cart they redirect back to the cart route, and
therefore to the configured URL.

Configuration
=============

Go to *Website > Configuration > Settings > Disabled Cart* and set
**Cart Redirect URL**: the internal path visitors land on when they reach a
standard cart URL.

- Default: ``/shop``.
- Stored in the system parameter ``website_sale_disable_cart.redirect_url``.
- Only site-internal paths are accepted. Absolute URLs (``https://...``) and
  protocol relative URLs (``//host/path``) are ignored — otherwise the shop
  could be used as an open redirect — as is any path under ``/shop/cart``,
  which would loop back into a disabled route. In those cases ``/shop`` is
  used and a warning is logged.

Example: on a site running ``website_sale_aplicoop``, set it to ``/eskaera`` so
that every standard cart URL lands on the group order flow.

Usage
=====

There is nothing to do at runtime: once installed, the cart is disabled site
wide. To go back to the standard behaviour, uninstall the module — all template
modifications are removed with it and the ``website_sale`` cart works again as
usual.

Files involved
==============

- ``controllers/website_sale.py`` — overrides the ``website_sale`` cart routes.
- ``views/website_sale_disable_cart_templates.xml`` — templates that hide the
  cart UI.
- ``models/res_config_settings.py`` and ``views/res_config_settings_views.xml``
  — the redirect URL setting.

Installation
============

::

    docker-compose run --rm odoo odoo -d odoo -i website_sale_disable_cart --stop-after-init
    docker-compose up -d

Testing
=======

::

    docker-compose run --rm odoo odoo -d odoo --test-enable --stop-after-init -u website_sale_disable_cart

Credits
=======

**Authors:**

* Criptomart

**History:**

This behaviour was originally implemented inside ``website_sale_aplicoop`` and
was extracted into this module so that it can be installed and configured
independently of the group order flow.

License
=======

AGPL-3. See ``LICENSE.txt`` or
https://www.gnu.org/licenses/agpl-3.0-standalone.html