Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
2173 มุมมอง

How we can create a dropdown in website listing the variants of the product selected?

please help.

Thanks.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello abc,

First you have to calculate product variants and pass to template and then display in template

# Calculate variants in controller

variants = request.env['products.product'].search([])

return request.render('template', {'variants': variants})

# display in template in dropdown format

<select>

<t t-foreach="variants" t-as="var">
    <option>

        <t t-esc="var.name"/>

    </option>

</t>

</select


Accept and upvote answer if helpful


Thanks and Regards

Haresh Kansara

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi
 at the beginning you have to inherit the function _prepare_qcontext from the table 'ir.ui.view', then add a for loop with variants of the product
then you have to make an xpath for the header

and then with a loop like that


<t t-foreach="product_list" t-as="product">

                                                                    <li>
                                                                        <a
                                                                            t-attf-href="/page/product/#{slug(
product['product_object'])}">
                                                                            <t t-esc="
product['product_name']" />
                                                                        </a>
                                                                    </li>
                                                                </t>


อวตาร
ละทิ้ง