Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Use new images named variants in emails and exports + improve docs (#13355)
Damian Legawiecee3884077ea4
diff --git a/core/app/helpers/spree/mail_helper.rb b/core/app/helpers/spree/mail_helper.rbindex 833b6e6d7b..0117547a55 100644--- a/core/app/helpers/spree/mail_helper.rb+++ b/core/app/helpers/spree/mail_helper.rb@@ -5,7 +5,7 @@ module Spreedef variant_image_url(variant)image = variant.default_image- image.present? && image.attached? ? spree_image_url(image, width: 100, height: 100, format: :png) : image_url('noimage/small.png')+ image.present? && image.attached? ? spree_image_url(image, variant: :mini) : image_url('noimage/small.png')enddef name_for(order)diff --git a/core/app/presenters/spree/csv/product_variant_presenter.rb b/core/app/presenters/spree/csv/product_variant_presenter.rbindex e45be07b57..863a078dd8 100644--- a/core/app/presenters/spree/csv/product_variant_presenter.rb+++ b/core/app/presenters/spree/csv/product_variant_presenter.rb@@ -135,10 +135,7 @@ module Spreeprivatedef image_url_options- {- width: 1000,- height: 1000- }+ { variant: :xlarge }endendenddiff --git a/core/lib/spree/core/configuration.rb b/core/lib/spree/core/configuration.rbindex 2344fef112..da24a4b0b6 100644--- a/core/lib/spree/core/configuration.rb+++ b/core/lib/spree/core/configuration.rb@@ -49,7 +49,7 @@ module Spree# Preprocessed product image variant sizes at 2x retina resolution.# These variants are generated on upload to reduce runtime processing.- # When using spree_image_tag, pass half these values (e.g., width: 64 for mini).+ # When using spree_image_tag, pass variant option instead of width and height.## Default sizes:# mini (128x128) - admin thumbnails, checkout line itemsdiff --git a/docs/developer/core-concepts/images-assets.mdx b/docs/developer/core-concepts/images-assets.mdxindex 4bbc966022..54a7fbb377 100644--- a/docs/developer/core-concepts/images-assets.mdx+++ b/docs/developer/core-concepts/images-assets.mdx@@ -135,7 +135,8 @@ asset.alt # Alt text (Spree::Image only)Spree uses [libvips](https://www.libvips.org/) for image processing. Images are automatically:- Converted to **WebP format** for optimal file size-- **Preprocessed on upload** using named variants for common sizes+- **Preprocessed on upload** using named variants for common sizes for Products+- **Processed on demand** for other models- **Cached** for subsequent requests### Installing libvips@@ -153,7 +154,11 @@ apk add vips### Preprocessed Named Variants-Product images (`Spree::Image`) use **preprocessed named variants** for optimal performance. When an image is uploaded, Spree automatically generates optimized versions in the background, so they're ready to serve immediately without on-demand processing.+<Warning>+ Preprocessed named variants are only available for product images (`Spree::Image`). For other models, images are processed on demand.+</Warning>++When an image is uploaded, Spree automatically generates optimized versions in the background, so they're ready to serve immediately without on-demand processing. You can still generate on-the-fly variants if you wish, but we recommend using the preprocessed named variants for optimal performance.#### Available Variant Sizes@@ -179,7 +184,7 @@ All variants are:# Get URL only<%= spree_image_url product.images.first, variant: :large %>-# Direct Active Storage access+# Command line (rails console)image.attachment.variant(:small)```@@ -244,20 +249,20 @@ For non-product images or custom dimensions, you can still generate variants on-```ruby# Resize to fit within dimensions (maintains aspect ratio)-image.variant(resize_to_limit: [400, 400])+spree_image_tag(image, width: 400, height: 400)# Resize and crop to exact dimensions-image.variant(resize_to_fill: [200, 200])+spree_image_tag(image, width: 200, height: 200, crop: true)# Resize by width only-image.variant(resize_to_limit: [300, nil])+spree_image_tag(image, width: 300, height: nil)# Resize by height only-image.variant(resize_to_limit: [nil, 300])+spree_image_tag(image, width: nil, height: 300)```<Info>- Dynamic variants are generated on first request and cached. For frequently accessed images, consider using preprocessed named variants instead.+ Dynamic variants are generated on first request and cached.</Info>## Helpersdiff --git a/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb b/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erbindex 13f39c6879..00495b048a 100644--- a/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb+++ b/emails/app/views/spree/shared/purchased_items_table/_line_item.html.erb@@ -1,6 +1,11 @@<tr><td class="purchase_image">- <%= link_to(image_tag(variant_image_url(line_item.variant)), spree_storefront_resource_url(line_item.product)) %>+ <% image = line_item.variant.default_image %>+ <% if image.present? && image.attached? %>+ <%= link_to(spree_image_tag(image, variant: :mini, alt: line_item.name), spree_storefront_resource_url(line_item.product)) %>+ <% else %>+ <%= link_to(image_tag('noimage/small.png', alt: line_item.name), spree_storefront_resource_url(line_item.product)) %>+ <% end %></td><td class="purchase_item"><strong>diff --git a/emails/spec/helpers/spree/mail_helper_spec.rb b/emails/spec/helpers/spree/mail_helper_spec.rbindex f2bed4537b..8079e59431 100644--- a/emails/spec/helpers/spree/mail_helper_spec.rb+++ b/emails/spec/helpers/spree/mail_helper_spec.rb@@ -27,7 +27,7 @@ module Spreelet(:image) { create(:image) }specify 'returns proper image path' do- expect(subject).to eq spree_image_url(image, width: 100, height: 100, format: :png)+ expect(subject).to eq spree_image_url(image, variant: :mini)endendend