Answers.Body: <p>You can use something like this</p>
  <pre><code>{% for item in cart.lineItems %}
      {% set product = craft.products().hasVariant(craft.variants().id(item.purchasableId)).with([['variantThumb', { withTransforms: 'cartThumb'}]]).one() %}
      {% set cartThumb = product.variantThumb[0] %}
      {{ macro.checkoutThumb(cartThumb) }}
  {% endfor %}
  </code></pre>
  <p>I am not sure if there will be any significant change on the amount of the queries thought.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-04-13T12:07:24.167Z
Answers.LastActivityDate: 2022-04-13T12:07:24.167Z
Answers.UserDisplayName: codechrisz
Body: <p>The cart of Craft Commerce can't really be cached so I try to increase performance by loading product images in the cart via eager-loading.</p>
  <p>All tutorials tell me to use the <code>.with(['variantThumb'])</code>. But <code>.with</code> can only be used on the <code>craft.entries().section</code> and not on simple loops, I don't understand how to do this.</p>
  <p>The stuff in the cart is available via the <code>cart</code> handle:</p>
  <pre><code>{% for item in cart.lineItems %}
      {% set cartThumb = item.purchasable.variantThumb.one() %}
      {{ macro.checkoutThumb(cartThumb) }}
  {% endfor %}
  </code></pre>
  <p>I don't understand how to use eager-loading in this case.</p>
  
Tags: <plugin-craftcommerce><image><performance><eager-loading>
Title: Eager-Loading Cart images
ThreadText: # Eager-Loading Cart images
  
  (Asked by: username_0 on 2022-02-07)
  
  The cart of Craft Commerce can't really be cached so I try to increase performance by loading product images in the cart via eager-loading.
  
  All tutorials tell me to use the `.with(['variantThumb'])`. But `.with` can only be used on the `craft.entries().section` and not on simple loops, I don't understand how to do this.
  
  The stuff in the cart is available via the `cart` handle:
  
  ```
  {% for item in cart.lineItems %}
      {% set cartThumb = item.purchasable.variantThumb.one() %}
      {{ macro.checkoutThumb(cartThumb) }}
  {% endfor %}
  
  ```
  
  I don't understand how to use eager-loading in this case.
  
  **Tags:** plugin-craftcommerce, image, performance, eager-loading
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-04-13. Score: 1
  
  You can use something like this
  
  ```
  {% for item in cart.lineItems %}
      {% set product = craft.products().hasVariant(craft.variants().id(item.purchasableId)).with([['variantThumb', { withTransforms: 'cartThumb'}]]).one() %}
      {% set cartThumb = product.variantThumb[0] %}
      {{ macro.checkoutThumb(cartThumb) }}
  {% endfor %}
  
  ```
  
  I am not sure if there will be any significant change on the amount of the queries thought.
  
  
  ---
  
  