| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<odoo> |
| 3 |
|
| 4 |
<!-- ==== Main template ==== --> |
| 5 |
<!-- Product tiles. Used on the /shop page, the wishlist and the snippet. --> |
| 6 |
<!-- TODO: rename `products_item` to `product_tile` --> |
| 7 |
<template id="website_sale.products_item" name="Products item"> |
| 8 |
<!-- Parameters: |
| 9 |
- show_variations: Whether to show the variant preview on the tile. |
| 10 |
- show_ribbons: Whether to show the ribbons. |
| 11 |
- product: `product.template` record. |
| 12 |
- product_variant: `product.product` record. |
| 13 |
--> |
| 14 |
<t t-set="show_variations" t-value="True if show_variations is None else show_variations"/> |
| 15 |
<t t-set="show_ribbons" t-value="True if show_ribbons is None else show_ribbons"/> |
| 16 |
|
| 17 |
<!-- Variations/Attributes --> |
| 18 |
<t t-if="show_variations"> |
| 19 |
<t |
| 20 |
t-set="product_ptavs_data" |
| 21 |
t-value="previewed_attribute_values[product.id]" |
| 22 |
/> |
| 23 |
<t t-if="product_ptavs_data"> |
| 24 |
<t |
| 25 |
t-set="product_ptavs" |
| 26 |
t-value="product_ptavs_data.get('ptavs_data')" |
| 27 |
/> |
| 28 |
<t |
| 29 |
t-if="product_ptavs[0]['ptav'].attribute_id.preview_variants == 'hover'" |
| 30 |
t-set="ptavs_classes" |
| 31 |
t-value="'o_has_variations o_has_variations_onhover'" |
| 32 |
/> |
| 33 |
<t |
| 34 |
t-else="" |
| 35 |
t-set="ptavs_classes" |
| 36 |
t-value="'o_has_variations o_has_variations_static'" |
| 37 |
/> |
| 38 |
</t> |
| 39 |
</t> |
| 40 |
|
| 41 |
<form |
| 42 |
t-attf-class="oe_product_cart h-100 d-flex {{ptavs_classes}}" |
| 43 |
t-att-data-publish="product.website_published and 'on' or 'off'" |
| 44 |
role="article" |
| 45 |
t-att-aria-label="product.name" |
| 46 |
> |
| 47 |
<div t-attf-class="oe_product_image position-relative flex-grow-0 overflow-hidden"> |
| 48 |
<input |
| 49 |
type="hidden" |
| 50 |
name="csrf_token" |
| 51 |
t-att-value="request.csrf_token()" |
| 52 |
/> |
| 53 |
|
| 54 |
<!-- Fetch Images Data --> |
| 55 |
<!-- Use `variant` instead of reassigning `product_variant` beacause it's used to infer |
| 56 |
if variant information should be shown later. --> |
| 57 |
<t |
| 58 |
t-set="variant" |
| 59 |
t-value="product_variant or product_variants[product]" |
| 60 |
/> |
| 61 |
<t |
| 62 |
t-if="variant and variant.with_context(bin_size=True).image_128" |
| 63 |
t-set="all_images_list" |
| 64 |
t-value="variant._get_images()" |
| 65 |
/> |
| 66 |
<t |
| 67 |
t-else="" |
| 68 |
t-set="all_images_list" |
| 69 |
t-value="product._get_images()" |
| 70 |
/> |
| 71 |
<!-- |
| 72 |
Image holders are records of different types (`product.template`, `product.product` |
| 73 |
or `product.image`) and are returned as a list. |
| 74 |
--> |
| 75 |
<t |
| 76 |
t-set="primary_image_holder" |
| 77 |
t-value="(all_images_list[:1]+[product])[0]" |
| 78 |
/> |
| 79 |
<t |
| 80 |
t-set="secondary_image_holder" |
| 81 |
t-value="(all_images_list[1:2]+[False])[0]" |
| 82 |
/> |
| 83 |
|
| 84 |
<a |
| 85 |
t-att-href="product_href" |
| 86 |
t-attf-class="oe_product_image_link position-relative {{secondary_image_holder and 'oe_product_image_link_has_secondary'}}" |
| 87 |
contenteditable="false" |
| 88 |
t-att-title="product.name" |
| 89 |
> |
| 90 |
<!-- Primary image --> |
| 91 |
<span |
| 92 |
t-field="primary_image_holder.image_1920" |
| 93 |
t-options="{'widget': 'image', 'preview_image': 'image_1024', 'class': 'oe_product_image_img h-100 w-100'}" |
| 94 |
class="oe_product_image_img_wrapper oe_product_image_img_wrapper_primary d-flex h-100 justify-content-center align-items-center" |
| 95 |
/> |
| 96 |
|
| 97 |
<!-- Secondary image --> |
| 98 |
<span |
| 99 |
t-if="secondary_image_holder" |
| 100 |
t-field="secondary_image_holder.image_1920" |
| 101 |
t-options="{'widget': 'image', 'preview_image': 'image_1024', 'class': 'oe_product_image_img_secondary h-100 w-100'}" |
| 102 |
class="oe_product_image_img_wrapper oe_product_image_img_wrapper_secondary h-100 justify-content-center align-items-center" |
| 103 |
/> |
| 104 |
|
| 105 |
<!-- Ribbon --> |
| 106 |
<t t-if="show_ribbons"> |
| 107 |
<t t-set="bg_color" t-value="ribbon.bg_color"/> |
| 108 |
<t t-set="text_color" t-value="ribbon.text_color"/> |
| 109 |
<span |
| 110 |
t-att-data-ribbon-id="ribbon.id" |
| 111 |
t-attf-class="o_ribbons o_not_editable #{ribbon._get_css_classes()}" |
| 112 |
t-attf-style="#{text_color and ('color: %s;' % text_color)} #{bg_color and 'background-color:' + bg_color}" |
| 113 |
t-out="ribbon.name or ''" |
| 114 |
/> |
| 115 |
</t> |
| 116 |
</a> |
| 117 |
</div> |
| 118 |
<div class="o_wsale_product_information flex-grow-1 flex-shrink-1"> |
| 119 |
<div class="o_wsale_product_info_attributes_wrapper"> |
| 120 |
<!-- Variations/Attributes --> |
| 121 |
<t |
| 122 |
t-if="product_ptavs_data" |
| 123 |
t-call="website_sale.product_variant_preview" |
| 124 |
/> |
| 125 |
|
| 126 |
<!-- Information --> |
| 127 |
<div class="o_wsale_product_information_text"> |
| 128 |
<!-- Product Name --> |
| 129 |
<h2 class="o_wsale_products_item_title text-break"> |
| 130 |
<a |
| 131 |
class="text-decoration-none" |
| 132 |
t-att-href="product_href" |
| 133 |
> |
| 134 |
<span t-field="product.name"/> |
| 135 |
<t |
| 136 |
t-if="product_variant" |
| 137 |
t-set="combination_name" |
| 138 |
t-value="product_variant.product_template_attribute_value_ids._get_combination_name()" |
| 139 |
/> |
| 140 |
<span |
| 141 |
t-if="combination_name" |
| 142 |
t-out="'('+combination_name+')'" |
| 143 |
/> |
| 144 |
</a> |
| 145 |
<a |
| 146 |
t-if="not product.website_published" |
| 147 |
role="button" |
| 148 |
t-att-href="product_href" |
| 149 |
class="btn btn-sm btn-danger" |
| 150 |
title="This product is unpublished." |
| 151 |
> |
| 152 |
Unpublished |
| 153 |
</a> |
| 154 |
</h2> |
| 155 |
<!-- Description --> |
| 156 |
<t t-call="website_sale.product_tile_element_visibility"> |
| 157 |
<t t-set="visible_element_class" t-value="'o_wsale_products_opt_has_description'"/> |
| 158 |
|
| 159 |
<div class="oe_subdescription_wrapper"> |
| 160 |
<div |
| 161 |
class="oe_subdescription text-muted small" |
| 162 |
contenteditable="false" |
| 163 |
> |
| 164 |
<div t-field="product.description_sale"/> |
| 165 |
</div> |
| 166 |
</div> |
| 167 |
</t> |
| 168 |
<!-- Rating --> |
| 169 |
<t |
| 170 |
t-if="is_view_active('website_sale.product_comment')" |
| 171 |
t-call="website_sale.product_tile_element_visibility" |
| 172 |
> |
| 173 |
<t t-set="visible_element_class" t-value="'o_wsale_products_opt_has_rating'"/> |
| 174 |
|
| 175 |
<div class="o_wsale_product_rating_wrapper"> |
| 176 |
<t t-call="portal_rating.rating_widget_stars_static"> |
| 177 |
<!-- sudo: product.product - visitor can access product average rating --> |
| 178 |
<t t-set="rating_avg" t-value="product.sudo().rating_avg"/> |
| 179 |
<t t-set="rating_count" t-value="product.rating_count"/> |
| 180 |
</t> |
| 181 |
</div> |
| 182 |
</t> |
| 183 |
<t t-if="product_extra_information" t-out="product_extra_information"/> |
| 184 |
</div> |
| 185 |
</div> |
| 186 |
<div class="o_wsale_product_sub justify-content-between gap-2"> |
| 187 |
<!-- Price(s) --> |
| 188 |
<t t-if="product_price" t-out="product_price"/> |
| 189 |
<t t-else=""> |
| 190 |
<t t-set="template_price_vals" t-value="get_product_prices(product)"/> |
| 191 |
<div class="product_price" aria-label="Price information"> |
| 192 |
<span |
| 193 |
class="mb-0 fw-bold" |
| 194 |
aria-label="Sale price" |
| 195 |
t-if="template_price_vals['price_reduce'] or not website.prevent_zero_price_sale" |
| 196 |
t-out="template_price_vals['price_reduce']" |
| 197 |
t-options="{'widget': 'monetary', 'display_currency': website.currency_id}" |
| 198 |
/> |
| 199 |
<t |
| 200 |
t-if="'base_price' in template_price_vals and (template_price_vals['base_price'] > template_price_vals['price_reduce']) and (template_price_vals['price_reduce'] or not website.prevent_zero_price_sale)" |
| 201 |
name="product_base_price" |
| 202 |
> |
| 203 |
<del |
| 204 |
aria-label="Original price" |
| 205 |
t-attf-class="text-muted me-1 mb-0" |
| 206 |
style="white-space: nowrap;" |
| 207 |
> |
| 208 |
<small |
| 209 |
t-esc="template_price_vals['base_price']" |
| 210 |
t-options="{'widget': 'monetary', 'display_currency': website.currency_id}" |
| 211 |
/> |
| 212 |
</del> |
| 213 |
</t> |
| 214 |
</div> |
| 215 |
</t> |
| 216 |
<!-- Actions --> |
| 217 |
<div class="o_wsale_product_btn"> |
| 218 |
<t t-if="product_actions" t-out="product_actions"/> |
| 219 |
<t t-else="" t-call="website_sale.shop_product_buttons"/> |
| 220 |
</div> |
| 221 |
</div> |
| 222 |
<!-- Extra actions (wishlist remove, ...) --> |
| 223 |
<t t-if="extra_actions" t-out="extra_actions"/> |
| 224 |
</div> |
| 225 |
</form> |
| 226 |
</template> |
| 227 |
|
| 228 |
<!-- TODO: rename `shop_product_buttons` to `product_tile_actions` --> |
| 229 |
<template id="website_sale.shop_product_buttons" name="Products Actions"> |
| 230 |
<t name="buttons_container"> |
| 231 |
<div class="o_wsale_product_action_row"> |
| 232 |
<t |
| 233 |
t-if="product._website_show_quick_add()" |
| 234 |
t-call="website_sale.product_tile_element_visibility" |
| 235 |
> |
| 236 |
<t t-set="visible_element_class" t-value="'o_wsale_products_opt_has_cta'"/> |
| 237 |
<input name="product_id" t-att-value="variant.id" type="hidden"/> |
| 238 |
<input name="product_template_id" t-att-value="product.id" type="hidden"/> |
| 239 |
<input name="product_type" t-att-value="product.type" type="hidden"/> |
| 240 |
<!-- type="button" needed as default type in a `form` is "sumbit" --> |
| 241 |
<button |
| 242 |
type="button" |
| 243 |
class="o_wsale_product_btn_primary a-submit btn btn-primary" |
| 244 |
aria-label="Add to cart" |
| 245 |
title="Add to cart" |
| 246 |
t-att-data-show-quantity="is_view_active('website_sale.product_quantity')" |
| 247 |
> |
| 248 |
<i class="fa fa-fw fa-shopping-cart o_not-animable" role="presentation"/> |
| 249 |
<span class="o_label small ms-1">Add to Cart</span> |
| 250 |
</button> |
| 251 |
</t> |
| 252 |
</div> |
| 253 |
</t> |
| 254 |
</template> |
| 255 |
|
| 256 |
<!-- Utilities --> |
| 257 |
|
| 258 |
<!-- Product Element Visibility Logic: |
| 259 |
|
| 260 |
This template controls whether a product tile element (e.g., price, description) |
| 261 |
should be rendered in the DOM, depending on visibility settings and user role. |
| 262 |
|
| 263 |
Behavior: |
| 264 |
- If the element's CSS class (`visible_element_class`) is NOT present in `design_field`, |
| 265 |
it's marked as "editor-only" (i.e., not normally visible). |
| 266 |
- Such elements are only injected if the current user is a website editor. |
| 267 |
- Otherwise, the element is always included for all users. |
| 268 |
|
| 269 |
Purpose: |
| 270 |
- Enables a better editing experience by letting designers preview and toggle elements live. |
| 271 |
- Prevents rendering unused elements for visitors, reducing DOM size and improving performance. |
| 272 |
|
| 273 |
Parameters: |
| 274 |
- visible_element_class: The CSS class identifier for the element. |
| 275 |
- design_field: A list of element classes currently enabled for display. |
| 276 |
- product: The product template record. |
| 277 |
- product_variant: The specific product variant record. |
| 278 |
--> |
| 279 |
<template id="website_sale.product_tile_element_visibility" name="Product tile elements visibility"> |
| 280 |
<t |
| 281 |
t-set="show_only_in_editor_mode" |
| 282 |
t-value="visible_element_class and design_field and visible_element_class not in design_field" |
| 283 |
/> |
| 284 |
<t |
| 285 |
t-set="is_editor_user" |
| 286 |
t-value="request.env.user.has_group('website.group_website_designer')" |
| 287 |
/> |
| 288 |
|
| 289 |
<t t-if="(show_only_in_editor_mode and is_editor_user) or not show_only_in_editor_mode"> |
| 290 |
<t t-out="0"/> |
| 291 |
</t> |
| 292 |
</template> |
| 293 |
|
| 294 |
</odoo> |