This question has been flagged

I have overriden the product.packagings table to move from product.template to product.product where it should be (check \Github issue #8237).

Now I want to display packaging info on the website for each variant (aka product.product).

I insert a very crude qweb to test:

<table>

    <tbody>

         <t t-foreach="product.product_variant_ids[0].packaging_ids" t-as="packaging_id">

               <tr>

                    <td>​<span t-field="packaging_id.ean"/></td>

                    <td>​<span t-field="packaging_id.qty"/></td>

               </tr>

         </t>

      </tbody>

</table>


It works but (as expected) fetches values for the first variant found. I want the table to change according to the variant selected from the combination of variant values.

The problem here is that I didn't find the selected variant_id as it is built dynamically in javascript (by evaluating attribute value selections).

  • Is there a way to get the variant_id (product_id in website_sale.js) exposed as a variable in qweb so that I can use:

<t t-foreach="variant_id.packaging_ids" t-as="packaging_id">

  • How can I auto-update the table when the variant changes?

 


Using Odoo Community V8 on OpenSuse 42.2

Avatar
Discard

I know this has been a long time, but I’m trying to do something similar and have asked the question but no one has answered. Were you ever able to solve this? If so could you share your solution with me?

Your help is greatly appreciated.

Best Answer

Remove the [0] from your loop to get information for all your variants.

If you only want to display information for the selected variant, there are two ways of doing so:


1) For beginning developers.

Use some jQuery to read the 'value' attribute from the input element '.product_id'. This updates automatically when the selection changes. 

Add 't-attf-class="{{packaging_id.id}}" ' to the table row. 

Hide all table rows, and then show the one which has the right class.

You do this both on page load, and on 'product_id' attribute change.


2) For more advanced developers.

Extend the product configurator script.

The product configurator fetches the combination when the selection changes and updates the DOM. Just include the table cells in the stuff that it updates.


P.S. I included a sample code for this earlier, but the forum is buggy so it didn't save.

Avatar
Discard

Kind sir, could you please return and reinstate your example code for method 1? (Also do you have to do anything to enable Jquery in the Qweb editor or is it enabled by default?)