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.

Use CDN for product images, logos and favicons

Damian Legawiec107040cd15e5
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 9272c741b0..1c1ef7a8c9 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -61,9 +61,9 @@ module Spree
DEPRECATION
image_path ||= if current_store.logo.attached? && current_store.logo.variable?
- main_app.url_for(current_store.logo.variant(resize_to_limit: [244, 104]))
+ main_app.cdn_image_url(current_store.logo.variant(resize_to_limit: [244, 104]))
elsif current_store.logo.attached? && current_store.logo.image?
- main_app.url_for(current_store.logo)
+ main_app.cdn_image_url(current_store.logo)
else
'logo/spree_50.png'
end
@@ -76,7 +76,7 @@ module Spree
end
def spree_favicon_path
- main_app.url_for(current_store.favicon || 'favicon.ico')
+ main_app.cdn_image_url(current_store.favicon || 'favicon.ico')
end
def object
@@ -88,7 +88,7 @@ module Spree
if object.is_a? Spree::Product
image = default_image_for_product_or_variant(object)
- og_meta['og:image'] = main_app.url_for(image.attachment) if image&.attachment
+ og_meta['og:image'] = main_app.cdn_image_url(image.attachment) if image&.attachment
og_meta['og:url'] = spree.url_for(object) if frontend_available? # url_for product needed
og_meta['og:type'] = object.class.name.demodulize.downcase
@@ -238,7 +238,7 @@ module Spree
def create_product_image_tag(image, product, options, style)
options[:alt] = image.alt.blank? ? product.name : image.alt
- image_tag main_app.url_for(image.url(style)), options
+ image_tag main_app.cdn_image_url(image.url(style)), options
end
def define_image_method(style)
@@ -249,7 +249,7 @@ module Spree
img = if image_path.present?
create_product_image_tag image_path, product, options, style
else
- inline_svg_tag "noimage/backend-missing-image.svg", class: "noimage", size: "60%*60%"
+ inline_svg_tag 'noimage/backend-missing-image.svg', class: 'noimage', size: '60%*60%'
end
content_tag(:div, img, class: "admin-product-image-container #{style}-img")