- Sustainability badge field on
product.template(Eco, Organic, Recycled) - Badge display on product cards and product detail pages
- Shop controller extension to filter by badge type
- A "Gift Message" field added to checkout with custom validation
- Email template that includes the gift message in the order confirmation
Feature 1: Sustainability Badge
Extend product.template to add a sustainability badge field:
# models/product_template.py
from odoo import models, fields
class ProductTemplate(models.Model):
_inherit = 'product.template'
sustainability_badge = fields.Selection([
('none', 'None'),
('eco', 'Eco-Friendly'),
('organic', 'Organic'),
('recycled', 'Made from Recycled Materials'),
], string='Sustainability Badge', default='none')
Display the badge on the product card by extending the shop template with XPath. Add a colored ribbon using Bootstrap utility classes and a CSS data attribute for the badge type.
Feature 2: Shop Filter by Badge
Extend the shop's search domain to support filtering by badge type:
# controllers/main.py
from odoo.addons.website_sale.controllers.main import WebsiteSale
class EcoShop(WebsiteSale):
def _get_search_domain(self, search, category, attrib_values,
search_in_description=True):
domain = super()._get_search_domain(
search, category, attrib_values, search_in_description
)
badge = request.params.get('badge')
if badge and badge != 'all':
domain += [('sustainability_badge', '=', badge)]
return domain
def shop(self, page=0, category=None, search='', **post):
response = super().shop(
page=page, category=category, search=search, **post
)
response.qcontext['current_badge'] = post.get('badge', 'all')
response.qcontext['badge_options'] = [
('all', 'All Products'),
('eco', 'Eco-Friendly'),
('organic', 'Organic'),
('recycled', 'Recycled Materials'),
]
return response
Feature 3: Gift Message at Checkout
Add a gift message field to sale.order and capture it at checkout:
# models/sale_order.py
from odoo import models, fields
class SaleOrder(models.Model):
_inherit = 'sale.order'
gift_message = fields.Text(string='Gift Message')
is_gift = fields.Boolean(string='This is a Gift')
Extend the checkout template to add a gift message section, and override _checkout_form_save() in the controller to persist the field:
class EcoShop(WebsiteSale):
def _checkout_form_save(self, mode, checkout, all_values):
order = request.website.sale_get_order()
is_gift = bool(all_values.get('is_gift'))
gift_message = (all_values.get('gift_message') or '').strip()
if is_gift and not gift_message:
return {'errors': {'gift_message': 'Gift message is required.'}}
order.write({
'is_gift': is_gift,
'gift_message': gift_message if is_gift else '',
})
return super()._checkout_form_save(mode, checkout, all_values)
Feature 4: Gift Message in Order Email
Extend the sale order confirmation email template to include the gift message:
<template id="sale_email_gift_extension"
inherit_id="sale.mail_template_sale_confirmation">
<xpath expr="//div[@name='order_lines']" position="before">
<t t-if="object.is_gift">
<div style="background: #f8f9fa; padding: 12px; margin-bottom: 16px;
border-left: 4px solid #28a745; border-radius: 4px;">
<strong>🎁 Gift Order</strong>
<p style="margin: 8px 0 0;">
<em><t t-out="object.gift_message"/></em>
</p>
</div>
</t>
</xpath>
</template>
- Add a "sustainability score" computed field that aggregates badge count across a product category
- Build a website snippet that shows top eco-friendly products dynamically
- Add a discount for orders over €100 that are marked as gifts
- Create a backend report showing total gift orders by month