Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

How do I add a field (internal reference) to products page on webiste?

Avatar
odoo
Avatar
Discard
4 Answers
0
Avatar
odoo
Best Answer

Hi,

Hi, While changing the product variant a javascript function (_onChangeCombination) is running behind to get the product detail of the variant. You can overide the function to change the default product code according to the attribute change.
First add the following code in the html view (<template id="product">) inside the div

<div class="js_product js_main_product">
<span t-attf-class="default_code" t-field="product.default_code"/>
</div>

then inherit the javascript function (_onChangeCombination) and find the html element.

var $default_code = $parent.find(".default_code");

provide the value for the variable.

$default_code.text(combination.default_code);

You can pass the default_code from the python fuction _get_combination_info()

'default_code': product.default_code

Regards

2 Comments
Avatar
Discard
Avatar
odoo
-

Thanks so much for the response. So am I able to do this since I'm using Odoo online? I'm not sure where to inherit the javascript function and pass the defualt_code from the python function. Could you elaborate more on this please.

Avatar
odoo
-

Is this the correct way?
<div class="js_product js_main_product">
<span t-attf-class="default_code" t-field="product.default_code"/>
</div>

I also extend the JS you mentioned and I found my JS is called but the value is not changed when we change variant.

0
Avatar
odoo
Best Answer

Simplest way without coding:

On backend: Website -> Configuration (on top menu) -> Websites -> YourWebsiteName -> Product Page Extra Fields (Tab) ->Add Line (Internal Reference).

Go to product page and there is displayed Internal Reference.

Thats all ;)

Avatar
Discard
0
Avatar
odoo
Best Answer

Ok, I figured it out.  Here is what I did in case it helps anyone else.

On the shopping cart, edit HTML, from the dropdown select Shopping Cart Lines.

<div>
    <t t-call="website_sale.cart_line_product_link">
        <strong t-field="line.product_id.product_tmpl_id"/>
    </t>
</div>

I changed the field in bold so that it now shows [internal reference] Product Name

On the product detail view:

<h1 itemprop="name" t-field="product.name">Product Name</h1>
<span t-field="product.default_code"/>

I added the line in bold so that the internal reference is now displayed underneath the product name.

On the main product page (table view):

<div class="oe_product_cart" t-att-data-publish="product.website_published and 'on' or 'off'">
    <t t-set="product_image_big" t-value="td_product['x']+td_product['y'] &gt; 2"/>
        <t t-call="website_sale.products_item"/>
</div>
<div style="margin-left:10px">
    <t t-if="product.default_code">
        <t t-set="int_ref" t-value="'pn: '+product.default_code" />
            <p t-esc="int_ref" class="text-muted"/>
        </t>
</div>

I added the code in bold. This is the best I could do here.  This will display the Internal Reference at the bottom of each tile.  I would have prefered to show it under the Product Name, but was not able to figure that out.  If anyone has any ideas here that would be great.  I just added the "pn: " to simply prefix the default code with.

1 Comment
Avatar
Discard
Avatar
odoo
-

So although this works, on the product detail view, if you use products with variants it does not show properly. I can see that the images for the variants are fetched, but the variant_id is not passed to the qweb view.

I tried to use product_variant.default_code but it will only show the initial internal reference. When you change a variant option, the default_code is not updated.

Does anyone know how to get the default_code for the variant?

0
Avatar
odoo
Best Answer

Hi Pierre

Were you able to find a solution to your default_code value with variants?

1 Comment
Avatar
Discard
Avatar
odoo
-

Unfortunately no. We have Odoo Online (SaaS) version, so we don't necessarily have full access to the source code as suggested below.