Answers.Body: <p>This is a gotcha with the recent move to emails being sent by the queue and not during the actual checkout process.</p>
  <p>Your problem is this line (and other lines you might have like it...):</p>
  <pre><code>variant.salePrice|commerceCurrency(craft.commerce.carts.cart.currency)
  </code></pre>
  <p>...when the queue runs, there is no current <code>cart</code> for the commerce carts service to retrieve, so therefore you also can't retrieve the currency from it.</p>
  <p>If you change this to something direct, i.e. using the Craft currency filter, it will not raise this error.</p>
  <p><a href="https://docs.craftcms.com/v3/dev/filters.html#currency" rel="nofollow noreferrer">https://docs.craftcms.com/v3/dev/filters.html#currency</a></p>
  <pre><code>variant.salePrice|currency('AUD')
  </code></pre>
  <p>...for example.</p>
  <p>This is fine if your store only uses one currency.</p>
  <p>If you are using multi currency, then I think you would need to retrieve the <code>order.paymentCurrency</code> in this case.</p>
  <p><a href="https://docs.craftcms.com/commerce/v3/payment-currencies.html#order-currency-fields" rel="nofollow noreferrer">https://docs.craftcms.com/commerce/v3/payment-currencies.html#order-currency-fields</a></p>
  <p>...in short, the one thing you can't do is call on the current <code>cart</code>....because there isn't one for console (queue) requests.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-04T15:51:10.050Z
Answers.Text: Thanks for your help, this solution solved the problem!
Answers.UserDisplayName: chlsydkysr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-04T22:07:39.360Z
Answers.Text: That is good to hear!
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-03T22:03:56.633Z
Answers.LastActivityDate: 2020-08-04T22:08:29.943Z
Answers.LastEditDate: 2020-08-04T22:08:29.943Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I get the following error on multiple order mails from Craft Commerce. The error points out to the lines where a macro is called:</p>
  <pre><code>Email template parse error for email “New order”. Order: “e35f244”. Template error: “An exception has been thrown during the rendering of a template (&quot;Session does not exist in a console request.&quot;)
  </code></pre>
  <p>I've also seen this same error on other custom functions in the queue, but this got solved by performing a DB command instead of setting the field values directly on the element followed by the saveElement function, so the error does not only happen in this specific situation.</p>
  <p>The mail template:</p>
  <pre><code>{% import &quot;_macros/commerce&quot; as macroCommerce %}
  
  {% block content %}
  
      {% set language = &quot;nl&quot; %}
      
      {% set lineItemsList = {} %}
      {% for lineItem in order.lineItems %}
          {% set lineItemsListItem = {} %}
          {% set lineItemsListItem = lineItemsListItem|merge([&quot;#{lineItem.qty} x #{lineItem.description}&quot;]) %}
          {% if lineItem.purchasable.product.type.hasVariants %}
              {% set variantLabel = macroCommerce.getVariantLabel(lineItem.purchasable, true)|trim|striptags %}
              {% if variantLabel %}
                  {% set lineItemsListItem = lineItemsListItem|merge([variantLabel]) %}
              {% endif %}
          {% endif %}
  
          {% set lineItemsList = lineItemsList|merge([lineItemsListItem|join(&quot; - &quot;)]) %}
      {% endfor %}
  
      {% set body = &quot;#{&quot;orders_new_products&quot;|t(&quot;app&quot;, null, language = language)}
          #{lineItemsList}&quot;
      %}
      
      {% include &quot;_emails/template&quot; %}
  
  {% endblock %}
  </code></pre>
  <p>The getVariantLabel macro function in _macros/commerce.twig:</p>
  <pre><code>{% macro getVariantLabel(variant, showPrice = false) %}
      {% set variantLabel = {} %}
      {% set variantFields = variant.variantFields.one() %}
  
      {% if variantFields %}
          {% if variantFields.potSize %}
              {% set variantLabel = variantLabel|merge([variantFields.potSize]) %}
          {% endif %}
  
          {% if variantFields.color %}
              {% set variantLabel = variantLabel|merge([variantFields.color]) %}
          {% endif %}
      {% endif %}
  
      {% if showPrice %}
          {% set variantLabel = variantLabel|merge([variant.salePrice|commerceCurrency(craft.commerce.carts.cart.currency)]) %}
      {% endif %}
  
      {{ variantLabel|join(&quot; - &quot;) }}
  {% endmacro %}
  </code></pre>
  <p>When the mails are sent manually from the order detailpage it does succeed. There is a cronjob set on the server that keeps the queue running automatically to keep all the functions running in the queue, so I guess that it has something to do with this.</p>
  <p>Any solution or tips that could point me in the right direction are much appreciated!</p>
  
Tags: <plugin-craftcommerce><error><macro><error-templates><queue>
Title: Error on functions in queue: "Session does not exist in a console request."
ThreadText: # Error on functions in queue: "Session does not exist in a console request."
  
  (Asked by: username_0 on 2020-08-03)
  
  I get the following error on multiple order mails from Craft Commerce. The error points out to the lines where a macro is called:
  
  ```
  Email template parse error for email “New order”. Order: “e35f244”. Template error: “An exception has been thrown during the rendering of a template ("Session does not exist in a console request.")
  
  ```
  
  I've also seen this same error on other custom functions in the queue, but this got solved by performing a DB command instead of setting the field values directly on the element followed by the saveElement function, so the error does not only happen in this specific situation.
  
  The mail template:
  
  ```
  {% import "_macros/commerce" as macroCommerce %}
  
  {% block content %}
  
      {% set language = "nl" %}
      
      {% set lineItemsList = {} %}
      {% for lineItem in order.lineItems %}
          {% set lineItemsListItem = {} %}
          {% set lineItemsListItem = lineItemsListItem|merge(["#{lineItem.qty} x #{lineItem.description}"]) %}
          {% if lineItem.purchasable.product.type.hasVariants %}
              {% set variantLabel = macroCommerce.getVariantLabel(lineItem.purchasable, true)|trim|striptags %}
              {% if variantLabel %}
                  {% set lineItemsListItem = lineItemsListItem|merge([variantLabel]) %}
              {% endif %}
          {% endif %}
  
          {% set lineItemsList = lineItemsList|merge([lineItemsListItem|join(" - ")]) %}
      {% endfor %}
  
      {% set body = "#{"orders_new_products"|t("app", null, language = language)}
          #{lineItemsList}"
      %}
      
      {% include "_emails/template" %}
  
  {% endblock %}
  
  ```
  
  The getVariantLabel macro function in \_macros/commerce.twig:
  
  ```
  {% macro getVariantLabel(variant, showPrice = false) %}
      {% set variantLabel = {} %}
      {% set variantFields = variant.variantFields.one() %}
  
      {% if variantFields %}
          {% if variantFields.potSize %}
              {% set variantLabel = variantLabel|merge([variantFields.potSize]) %}
          {% endif %}
  
          {% if variantFields.color %}
              {% set variantLabel = variantLabel|merge([variantFields.color]) %}
          {% endif %}
      {% endif %}
  
      {% if showPrice %}
          {% set variantLabel = variantLabel|merge([variant.salePrice|commerceCurrency(craft.commerce.carts.cart.currency)]) %}
      {% endif %}
  
      {{ variantLabel|join(" - ") }}
  {% endmacro %}
  
  ```
  
  When the mails are sent manually from the order detailpage it does succeed. There is a cronjob set on the server that keeps the queue running automatically to keep all the functions running in the queue, so I guess that it has something to do with this.
  
  Any solution or tips that could point me in the right direction are much appreciated!
  
  **Tags:** plugin-craftcommerce, error, macro, error-templates, queue
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-08-03. Score: 1 | Accepted answer
  
  This is a gotcha with the recent move to emails being sent by the queue and not during the actual checkout process.
  
  Your problem is this line (and other lines you might have like it...):
  
  ```
  variant.salePrice|commerceCurrency(craft.commerce.carts.cart.currency)
  
  ```
  
  ...when the queue runs, there is no current `cart` for the commerce carts service to retrieve, so therefore you also can't retrieve the currency from it.
  
  If you change this to something direct, i.e. using the Craft currency filter, it will not raise this error.
  
  <https://docs.craftcms.com/v3/dev/filters.html#currency>
  
  ```
  variant.salePrice|currency('AUD')
  
  ```
  
  ...for example.
  
  This is fine if your store only uses one currency.
  
  If you are using multi currency, then I think you would need to retrieve the `order.paymentCurrency` in this case.
  
  <https://docs.craftcms.com/commerce/v3/payment-currencies.html#order-currency-fields>
  
  ...in short, the one thing you can't do is call on the current `cart`....because there isn't one for console (queue) requests.
  
  > **Comments:**
  > **username_0**: Thanks for your help, this solution solved the problem!  
  > **username_1**: That is good to hear!  
  
  ---
  
  