Skip to content

armgit / spree

Public Imported from GitHub
0

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.

[Skip CI] Docs: Images - fixed instructions how to reprocess existing images via background job

Damian Legawiec18174b392bcc
diff --git a/docs/developer/core-concepts/images-assets.mdx b/docs/developer/core-concepts/images-assets.mdx
index 2fc362ad8a..4bbc966022 100644
--- a/docs/developer/core-concepts/images-assets.mdx
+++ b/docs/developer/core-concepts/images-assets.mdx
@@ -209,16 +209,27 @@ end
#### Reprocessing Existing Images
-After changing variant sizes or upgrading Spree, reprocess existing images:
+After changing variant sizes or upgrading Spree, reprocess existing images in background jobs:
```ruby
-# Reprocess all product images (queues background jobs)
Spree::Image.find_each do |image|
- next unless image.attached?
- image.attachment.preprocess_variants
+ next unless image.attachment.attached?
+
+ blob = image.attachment.blob
+
+ %i[mini small medium large xlarge og_image].each do |variant_name|
+ transformations = Spree::Image.attachment_reflections['attachment']
+ .named_variants[variant_name]
+ .transformations
+
+ ActiveStorage::TransformJob.perform_later(blob, transformations)
+ end
end
+```
-# Or process synchronously (slower but immediate)
+Or process synchronously (slower but immediate)
+
+```ruby
Spree::Image.find_each do |image|
next unless image.attached?
[:mini, :small, :medium, :large, :xlarge].each do |variant_name|