This question has been flagged
4 Replies
7695 Views

I'm trying to figure out how to add a field, in this case "internal reference" to my ecommerce products.

I would like to have it in the product tiles under the product name.  I would also like to have it show up next to the product name in the shopping cart lines.

I'm using Odoo online.

I was able to add it to the html for the product detail page by simply adding the following to the html code.

<span t-field="product.default_code"/>

I'm not sure where to go to edit it on the main products page and in the shopping cart description.

I'm guessing I need to edit the respective views but I'm not sure which.  Any help is greatly appreciated.    


Avatar
Discard
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

Avatar
Discard
Author

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.

Author 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.

Avatar
Discard
Author

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?

Best Answer

Hi Pierre

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

Avatar
Discard
Author

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

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