This question has been flagged
2 Replies
15237 Views

Hello,

I'm working on Shop page, and I need to add extra t-if condition to an existing one.

Here's the original code of  'website_sale.products_item' view:

<t name="Products item" t-name="website_sale.products_item">
    <form action="/shop/cart/update" method="post">
    <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
    <div itemscope="itemscope" itemtype="http://schema.org/Product">
        -
        -
        -
        <section>
             -
             -
             <div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price" t-if="product.product_variant_ids">
             -
             -        
         </section>
    </div></form>
</t>

 

What I need to do know is to add more condition to the highlighted tag above without losing it, but I don't know the proper way to achieve it.

Here's my code:

<template id="custom_solution_hide_products_price" inherit_id="website_sale.products_item" name="Hide Custom Solution Products Price">
 <xpath expr="//div[@class='product_price']" position="attributes">
  <attribute name="t-if">product.product_variant_ids and not product.custom_solution</attribute>
 </xpath>
</template>

But I don't think this is the right way of doing it, because I had to type the original condition in my code otherwise it will create conditions confliction.

Can anyone give me a tip to do it in the right way. Thanks


Avatar
Discard

I have add my new condition as below and it works fine.

<template id="products_test" inherit_id="website_sale.products_item" active="True" customize_show="False" name="Product test">

<xpath expr="//div[@class='product_price']" position="attributes">

<attribute name="t-if">product.product_variant_ids and product.lst_price &gt; 500</attribute>

</xpath>

</template>

In inherit view whatever you will set in if condition is finally get execute.

Best Answer

hello,

you can extend a template using t-extend :

<t t-extend="template_name">

    <t t-jquery="[div,span,button,etc].class_name" t-operation="[replace,after,before]">

        <-- your code -->

    </t>

</t>


for example :

<t t-extend="website_sale.products_item">

    <t t-jquery="div.product_price" t-operation="replace">

        <-- your code -->

    </t>

</t>

Avatar
Discard