Skip to content

Commit f0877c1

Browse files
committed
[ADD] website_sale_dynamic_review_snippet: Module added
1 parent 4fe7223 commit f0877c1

28 files changed

+1235
-0
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
======================
2+
Website Custom Snippet
3+
======================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:d43413aa9ae52f19e0b4b115657a500479b34562b7628473e4cdc7c3007976b2
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github
20+
:target: https://github.com/OCA/e-commerce/tree/18.0/website_sale_dynamic_review_snippet
21+
:alt: OCA/e-commerce
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/e-commerce-18-0/e-commerce-18-0-website_sale_dynamic_review_snippet
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
| This module provides a new website snippet that aggregates customer
32+
reviews from product templates.
33+
| It allows website administrators to display up to 100 reviews from one
34+
or more products in a single dynamic block, directly within the Odoo
35+
Website Builder.
36+
37+
| The snippet offers configuration options (maximum number of reviews)
38+
and renders reviews with rating stars, reviewer names, comments, and
39+
associated product names (if multiple products are chosen).
40+
| It is designed to be responsive and mobile-friendly, making it easy to
41+
showcase customer feedback on landing pages or promotional sections.
42+
43+
**Table of contents**
44+
45+
.. contents::
46+
:local:
47+
48+
Use Cases / Context
49+
===================
50+
51+
Business Need
52+
-------------
53+
54+
E-commerce websites often want to highlight customer feedback not only
55+
on individual product pages but also in centralized locations such as
56+
landing pages, category pages, or custom marketing sections.
57+
58+
By default, Odoo reviews are tied to specific products and cannot be
59+
easily aggregated or reused elsewhere on the website.
60+
61+
This module addresses this limitation by introducing a snippet that
62+
collects and displays multiple reviews in one place.
63+
64+
For example:
65+
66+
- A landing page showcasing testimonials from the most popular products.
67+
68+
- A category introduction page summarizing customer experiences.
69+
70+
- A homepage section displaying reviews from newly launched products.
71+
72+
Approach
73+
--------
74+
75+
The module extends the existing ``website_sale`` and ``website_rating``
76+
functionality to provide a configurable snippet.
77+
78+
The snippet fetches published reviews across selected products and
79+
displays them with a configurable limit (default 20, maximum 100).
80+
81+
Useful Information
82+
------------------
83+
84+
- **Dependencies:** Relies on ``website_sale`` and ``website_rating``.
85+
86+
- **Compatible modules:** Works well with marketing and promotional
87+
website features such as sliders, banners, or call-to-action snippets.
88+
89+
- **Suggested setups:** Useful in multi-website or multi-company
90+
scenarios where aggregated feedback should be highlighted across
91+
different contexts.
92+
93+
Usage
94+
=====
95+
96+
To use this module:
97+
98+
1. Go to the Website application.
99+
100+
2. Open the Website Builder (Edit → Add Blocks).
101+
102+
3. In the "Dynamic Snippets" section, drag and drop **Product Reviews
103+
Snippet** into your page.
104+
105+
|Insert Snippet|
106+
107+
4. Configure the snippet by adjusting the maximum number of reviews
108+
(default: 20, max: 100) and set two columns option.
109+
110+
|Configure Snippet|
111+
112+
5. Save your changes and publish the page.
113+
114+
The snippet will now display the aggregated reviews with rating
115+
stars, reviewer details, and comments.
116+
117+
|Rendered Snippet|
118+
119+
.. |Insert Snippet| image:: https://raw.githubusercontent.com/OCA/e-commerce/18.0/website_sale_dynamic_review_snippet/static/description/snippet_insert.png
120+
.. |Configure Snippet| image:: https://raw.githubusercontent.com/OCA/e-commerce/18.0/website_sale_dynamic_review_snippet/static/description/snippet_config.png
121+
.. |Rendered Snippet| image:: https://raw.githubusercontent.com/OCA/e-commerce/18.0/website_sale_dynamic_review_snippet/static/description/snippet_render.png
122+
123+
Bug Tracker
124+
===========
125+
126+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/e-commerce/issues>`_.
127+
In case of trouble, please check there if your issue has already been reported.
128+
If you spotted it first, help us to smash it by providing a detailed and welcomed
129+
`feedback <https://github.com/OCA/e-commerce/issues/new?body=module:%20website_sale_dynamic_review_snippet%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
130+
131+
Do not contact contributors directly about support or help with technical issues.
132+
133+
Credits
134+
=======
135+
136+
Authors
137+
-------
138+
139+
* XXP
140+
141+
Maintainers
142+
-----------
143+
144+
This module is maintained by the OCA.
145+
146+
.. image:: https://odoo-community.org/logo.png
147+
:alt: Odoo Community Association
148+
:target: https://odoo-community.org
149+
150+
OCA, or the Odoo Community Association, is a nonprofit organization whose
151+
mission is to support the collaborative development of Odoo features and
152+
promote its widespread use.
153+
154+
This module is part of the `OCA/e-commerce <https://github.com/OCA/e-commerce/tree/18.0/website_sale_dynamic_review_snippet>`_ project on GitHub.
155+
156+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import controllers
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "Website Custom Snippet",
3+
"version": "18.0.1.0.0",
4+
"category": "Website",
5+
"depends": ["website_sale"],
6+
"summary": (
7+
"Aggregate website users’ reviews from product templates into a single "
8+
"website snippet (configurable, up to 100 records) "
9+
"accessible in the Odoo Website Builder."
10+
),
11+
"author": "XXP, Odoo Community Association (OCA)",
12+
"license": "AGPL-3",
13+
"website": "https://github.com/OCA/e-commerce",
14+
"data": [
15+
"views/snippets/options.xml",
16+
"views/snippets/s_dynamic_review.xml",
17+
],
18+
"assets": {
19+
"portal.assets_chatter": [
20+
"website_sale_dynamic_review_snippet/static/src/core/*",
21+
"website_sale_dynamic_review_snippet/static/src/components/*",
22+
"website_sale_dynamic_review_snippet/static/src/services/*",
23+
],
24+
"web.assets_frontend": [
25+
"website_sale_dynamic_review_snippet/static/src/boot/boot_service.esm.js",
26+
],
27+
},
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from odoo.http import Controller, request, route
2+
3+
from odoo.addons.mail.tools.discuss import Store
4+
from odoo.addons.portal.utils import get_portal_partner
5+
6+
7+
class CustomerReview(Controller):
8+
@route(
9+
["/mail/review/messages"],
10+
methods=["POST"],
11+
type="json",
12+
auth="public",
13+
website=True,
14+
)
15+
def mail_review_messages(self, before=None, after=None, limit=30):
16+
domain = [
17+
("model", "=", "product.template"),
18+
("message_type", "=", "comment"),
19+
("rating_ids", "not in", []),
20+
]
21+
res = (
22+
request.env["mail.message"]
23+
.sudo()
24+
._message_fetch(domain, None, before, after, None, limit)
25+
)
26+
messages = res.pop("messages")
27+
messages_result = messages.portal_message_format(
28+
options={"rating_include": True}
29+
)
30+
for vals in messages_result:
31+
if not vals.get("model"):
32+
continue
33+
record = request.env[vals["model"]].sudo().browse(vals["res_id"])
34+
vals["thread"]["name"] = record.name
35+
vals["website_url"] = record.website_url
36+
return {
37+
**res,
38+
"data": {
39+
"mail.message": messages_result,
40+
},
41+
"messages": Store.many_ids(messages),
42+
}
43+
44+
@route("/portal/review_init", type="json", auth="public", website=True)
45+
def portal_review_init(self, **kwargs):
46+
store = Store()
47+
request.env["res.users"]._init_store_data(store)
48+
if request.env.user.has_group("website.group_website_restricted_editor"):
49+
store.add(request.env.user.partner_id, {"is_user_publisher": True})
50+
products = request.env["product.template"].search([("is_published", "=", True)])
51+
product_obj = request.env["product.template"]
52+
for product in products:
53+
thread = product_obj._get_thread_with_access(product.id, **kwargs)
54+
if thread:
55+
mode = product_obj._get_mail_message_access([product.id], "create")
56+
has_react_access = product_obj._get_thread_with_access(
57+
product.id, mode, **kwargs
58+
)
59+
if request.env.user._is_public():
60+
if portal_partner := get_portal_partner(
61+
thread,
62+
kwargs.get("hash"),
63+
kwargs.get("pid"),
64+
kwargs.get("token"),
65+
):
66+
store.add(
67+
thread,
68+
{
69+
"portal_partner": Store.one(
70+
portal_partner,
71+
fields=["active", "avatar_128", "name", "user"],
72+
)
73+
},
74+
as_thread=True,
75+
)
76+
can_react = has_react_access and portal_partner
77+
else:
78+
can_react = has_react_access
79+
store.add(
80+
thread,
81+
{
82+
"can_react": bool(can_react),
83+
"hasReadAccess": thread.sudo(False).has_access("read"),
84+
},
85+
as_thread=True,
86+
)
87+
return store.get_result()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## Business Need
2+
3+
E-commerce websites often want to highlight customer feedback not only on individual product pages but also in centralized locations such as landing pages, category pages, or custom marketing sections.
4+
5+
By default, Odoo reviews are tied to specific products and cannot be easily aggregated or reused elsewhere on the website.
6+
7+
8+
This module addresses this limitation by introducing a snippet that collects and displays multiple reviews in one place.
9+
10+
For example:
11+
12+
- A landing page showcasing testimonials from the most popular products.
13+
14+
- A category introduction page summarizing customer experiences.
15+
16+
- A homepage section displaying reviews from newly launched products.
17+
18+
19+
## Approach
20+
21+
The module extends the existing `website_sale` and `website_rating` functionality to provide a configurable snippet.
22+
23+
The snippet fetches published reviews across selected products and displays them with a configurable limit (default 20, maximum 100).
24+
25+
26+
## Useful Information
27+
28+
- **Dependencies:** Relies on `website_sale` and `website_rating`.
29+
30+
- **Compatible modules:** Works well with marketing and promotional website features such as sliders, banners, or call-to-action snippets.
31+
32+
- **Suggested setups:** Useful in multi-website or multi-company scenarios where aggregated feedback should be highlighted across different contexts.
33+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This module provides a new website snippet that aggregates customer reviews from product templates.
2+
It allows website administrators to display up to 100 reviews from one or more products in a single dynamic block, directly within the Odoo Website Builder.
3+
4+
5+
The snippet offers configuration options (maximum number of reviews) and renders reviews with rating stars, reviewer names, comments, and associated product names (if multiple products are chosen).
6+
It is designed to be responsive and mobile-friendly, making it easy to showcase customer feedback on landing pages or promotional sections.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
To use this module:
2+
3+
4+
1. Go to the Website application.
5+
6+
2. Open the Website Builder (Edit → Add Blocks).
7+
8+
3. In the "Dynamic Snippets" section, drag and drop **Product Reviews Snippet** into your page.
9+
10+
11+
![Insert Snippet](../static/description/snippet_insert.png)
12+
13+
14+
4. Configure the snippet by adjusting the maximum number of reviews (default: 20, max: 100) and set two columns option.
15+
16+
17+
![Configure Snippet](../static/description/snippet_config.png)
18+
19+
20+
5. Save your changes and publish the page.
21+
22+
The snippet will now display the aggregated reviews with rating stars, reviewer details, and comments.
23+
24+
25+
![Rendered Snippet](../static/description/snippet_render.png)
9.23 KB
Loading

0 commit comments

Comments
 (0)