|
| 1 | +import { patch } from "@web/core/utils/patch"; |
| 2 | +import { ProductCard } from "@pos_self_order/app/components/product_card/product_card"; |
| 3 | +import { ProductPage } from "@pos_self_order/app/pages/product_page/product_page"; |
| 4 | +import { markup } from "@odoo/owl"; |
| 5 | + |
| 6 | +// Patch ProductCard to always navigate to the product page on selection, |
| 7 | +// enabling display of self_order_description and large image for all products. |
| 8 | +patch(ProductCard.prototype, { |
| 9 | + async selectProduct(qty = 1) { |
| 10 | + const product = this.props.product; |
| 11 | + |
| 12 | + if (!product.self_order_available || !this.isAvailable) { |
| 13 | + return; |
| 14 | + } |
| 15 | + |
| 16 | + // For combo products, we use the default behavior |
| 17 | + if (product.isCombo()) { |
| 18 | + return super.selectProduct(qty); |
| 19 | + } |
| 20 | + |
| 21 | + // For other products, navigate to the product page |
| 22 | + this.router.navigate("product", { id: product.id }); |
| 23 | + } |
| 24 | +}); |
| 25 | + |
| 26 | +// Patch ProductPage component to fetch and display self_order_description |
| 27 | +patch(ProductPage.prototype, { |
| 28 | + async setup() { |
| 29 | + // call the original setup method to ensure the component is initialized properly |
| 30 | + super.setup(); |
| 31 | + |
| 32 | + // This ensures that the product's self_order_description is fetched |
| 33 | + const product = this.props.product; |
| 34 | + if (product && !product.self_order_description) { |
| 35 | + try { |
| 36 | + const orm = this.env.services.orm; |
| 37 | + // orm.read() returns all fields of product.product, including those added by other modules via _inherit = "product.product". |
| 38 | + const [record] = await orm.read("product.product",[product.id]); |
| 39 | + if (record && record.self_order_description) { |
| 40 | + // markup is used to safely render HTML content |
| 41 | + product.self_order_description = markup(record.self_order_description); |
| 42 | + } |
| 43 | + } catch (err) { |
| 44 | + console.error("Failed to fetch self_order_description via ORM:", err); |
| 45 | + } |
| 46 | + } |
| 47 | + }, |
| 48 | +}); |
0 commit comments