I want the add hyperlinks for every product on my eCommerce website in Odoo. Every product will have unique hyperlinks. I thought of creating a variable somewhere and using them in the
web-sale -> views -> templates_view.xml
but i couldn't made it.
How can I use a variable from a different module inside XML?
<p t-if="True" class="css_not_available_msg alert alert-warning">This combination
does not exist.
</p>
<h1 t-field="product.qty_available"/>
<div id="add_to_cart_wrap" class="d-inline">
<a role="button" id="add_to_cart"
class="btn btn-primary btn-lg js_check_product a-submit my-1 mr-1 px-5 font-weight-bold flex-grow-1"
href="#"><i class="fa fa-shopping-cart mr-2"/>ADD TO CART
</a>
<div id="product_option_block" class="d-inline-block align-middle"/>
</div>
for example, I have an app with the name "TEST_APP" and a module with
name = "test"
and it has a field
test_bool = fields.Boolean(string="Test field")
Field in different module and XML in the web-sale module.
How can I use this field inside of this XML?
Sorry, I ask a lot of questions but I think I should learn this first for a solution.
Maybe after I can add links for every product on the eCommerce web site.
I think you need to review Odoo documentation on how to extend templates :)
What you want is to inherit from website_sale.product
and do some xpaths to place yourself in the template. e.x. if you want to add your boolean test_bool and have that boolean on product, not another model, if it's to add it on a product...
So, some python and some xml. Don't forget to add website_sale in your depends key of your __manifest__
.
Python (product model):
from odoo import models, fields
class ProductTemplate(models.Model):
_inherit = 'product.template'
test_bool = fields.Boolean('Test Bool')
XML (inherit the template and put test_bool above the button "add to cart")
<template id="product" inherit_id="website_sale.product">
<xpath expr="//a[@id='add_to_cart']" position="before">
<span t-esc="product.test_bool"/>
</xpath>
</template>
Note: this will be ugly at this place :p
Hope it helped