0

I am building a shop with Drupal Commerce right now. I have a product that uses an Order item type, which supports a file upload. The same product also has some product attributes that load the product variations via Ajax. When I don't use a twig theme for full products view, everything works fine.

Even if I use a product--full.html.twig theme and just render {{ product }}, everything works fine. But when I start rendering the products parts like title, images, variations, body, etc... according to this documentation, Ajax validation of the upload file stopps working.

I just have a simple theme looking similar to this:

<div id="slideshow">
    {{ product.variation_field_product_images }}
</div>
<div id="sidebar">
    <span>{{ product.variation_price }}</span>
    <div>{{ product.variations }}</div>
</div>
<div id="product-body">
    <p>{{ product.body }}</p>
</div>

This all renders well and works like desired, until I add a product attribute like e.g. "color" which loads the products variations also via Ajax. When I then change the product products attribute/variation an Ajax-event is triggered and the Ajax validation of the upload field in the product variation (order item type) stopps working.

I'd be really happy, if someone could give me a hint, since I am not sure if I really should render the product variations as {{ product.variations }}, since many things in the above linked documentation don't seem to be correct anymore.

Thank you very much in advance

1 Answer 1

1

In the last step render the entire product variable and exclude the fields rendered before, even if there is only one field left to be rendered. By this you make sure any metadata attached to the variable gets rendered as well:

<div id="slideshow">
    {{ product.field_a }}
</div>
<div id="sidebar">
    <span>{{ product.field_b }}</span>
    <div>{{ product.field_c }}</div>
</div>
<div id="product-body">
    <p>{{ product|without('field_a', 'field_b', 'field_c') }}</p>
</div>
2
  • I <3 you! Thank you soooooooo much! That works like desired.
    – what ever
    Sep 11, 2022 at 22:37
  • Sorrily I can't upvote or check your answer due to reputation. But that really did the trick. Thank's a lot again. I think I wouldn't have figured that out on my own by just googling.
    – what ever
    Sep 12, 2022 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.