Score:0

How can I work with Twig when using the Display Suite module?

va flag

I am working with Commerce 2 and Display suite, i want to add a field to the presentation that when a product has a boolean field valued to true, do not display a field and display other with twig. Maybe this way im more clear: field in product: Variation and a boolean flag if flag = true dont show the variation "Add to cart" but "Coming soon"

The problem i want to solve is that when i have no stock "add to cart" pass to "out of stock" but i would like to shot "Coming soon" if a flag is true even is i do have stock or not.

Thanks for the time reading this!

cn flag
I suggest you check https://www.drupal.org/project/conditional_fields module for this.
Score:0
va flag

Well i manage to do what i asked, i added a new field to product that name is proximamente,i had to let the variation stay but i hide it from view, with a twig field i can show the things in the way i want

twig code:

{% set variable = commerce_product.product_id.value%}
{% if commerce_product.field_proximamente.value is null %}
{{ drupal_field('variations','commerce_product',variable,'add_to_cart') }}
{% elseif commerce_product.field_proximamente.value == true %}
<p class="proximamente-btn-view button--add-to-cart button button--primary js-form-submit form-submit is-disabled btn-primary btn">Próximamente</p>
{% else %}
{{ drupal_field('variations','commerce_product',variable,'add_to_cart') }}
{% endif %}

i guess is kinda simple but works for me, when the boolean field is true i show the "Próximamente" with all the classes that a variation in Commerce 2 has, the reason of the first " IF " is because i added that new field way later on the product, so some products might not have it enabled so i have to cover that part

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.