0

On Drupal 8, I installed Drupal Commerce 2

I want to modify the TWIG file of the products to show "Made in France", if the store country is France and made in Belgium, if the store country is Belgium.

How to display a message according to the country of the store ?

I would like to do this in the products TWIG file and in the stores TWIG file.

There is certainly a condition to be met but I do not know which one.

commerce-store--online--full.html.twig :

  {% if  (how to make the condition to check the store country) FR %}
    <div class="row mr-0 mb-3 ml-0 shadow d-flex flex-wrap flag-france">
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 p-3 bg-primary"></div>
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 bg-white d-flex align-self-center justify-content-center">
        <small class="font-weight-bold text-center">ENTREPRISE FRANÇAISE</small>
      </div>
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 p-3 bg-danger"></div>
    </div>
  {% elseif (how to make the condition to check the store country) BE %}
    <div class="row mr-0 mb-3 ml-0 shadow d-flex flex-wrap flag-belgique">
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 p-3 bg-primary"></div>
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 bg-white d-flex align-self-center justify-content-center">
        <small class="font-weight-bold text-center">ENTREPRISE BELGE</small>
      </div>
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 p-3 bg-danger"></div>
    </div>
  {% endif %}
2
  • The "store" you refer to is the commerce's actual store entity or something else? If it is a commerce store, You may look for it and then for its properties from the product entity directly inside the twig. Try to debug or kint the entities you have inside the twig.
    – Giuseppe
    Feb 5, 2021 at 9:56
  • @Giuseppe I updated my question, I don't know what you mean. I want to check the country of the store
    – yoyo
    Feb 5, 2021 at 15:02

1 Answer 1

0

For commerce-store--online--full.html.twig it should looks like:

  {% if store_entity.address.country_code == FR %}
    <div class="row mr-0 mb-3 ml-0 shadow d-flex flex-wrap flag-france">
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 p-3 bg-primary"></div>
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 bg-white d-flex align-self-center justify-content-center">
        <small class="font-weight-bold text-center">ENTREPRISE FRANÇAISE</small>
      </div>
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 p-3 bg-danger"></div>
    </div>
  {% elseif store_entity.address.country_code == BE %}
    <div class="row mr-0 mb-3 ml-0 shadow d-flex flex-wrap flag-belgique">
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 p-3 bg-primary"></div>
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 bg-white d-flex align-self-center justify-content-center">
        <small class="font-weight-bold text-center">ENTREPRISE BELGE</small>
      </div>
      <div class="col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4 p-3 bg-danger"></div>
    </div>
  {% endif %}
2
  • Thanks, I tested your code, but it doesn't display anything.
    – yoyo
    Feb 5, 2021 at 19:33
  • Do you have any value in the "store_entity.address.country_code" ? Also, try to check what we have using {{ dump(store_entity.address) }} Feb 8, 2021 at 12:10

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.