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.

* allow uploading favicon per store * display favicon of a current store

Łukasz Adamczyk35370c4502af
diff --git a/backend/app/controllers/spree/admin/stores_controller.rb b/backend/app/controllers/spree/admin/stores_controller.rb
index b0e2916df1..682cdf499f 100644
--- a/backend/app/controllers/spree/admin/stores_controller.rb
+++ b/backend/app/controllers/spree/admin/stores_controller.rb
@@ -58,7 +58,7 @@ module Spree
redirect_to admin_stores_path
else
flash[:error] = "#{Spree.t('store_errors.unable_to_update')}: #{@store.errors.full_messages.join(', ')}"
- render :edit
+ redirect_to edit_admin_store_path(@store)
end
end
diff --git a/backend/app/views/spree/admin/stores/_form.html.erb b/backend/app/views/spree/admin/stores/_form.html.erb
index dea55ca5b8..4594c54e48 100644
--- a/backend/app/views/spree/admin/stores/_form.html.erb
+++ b/backend/app/views/spree/admin/stores/_form.html.erb
@@ -29,14 +29,14 @@
<%= f.error_message_on :mailer_logo %>
<% end %>
<% end %>
- <%= f.field_container :favicon, class: ['form-group'] do %>
- <% if @store.favicon.attached? && @store.favicon.variable? %>
- <%= image_tag main_app.url_for(@store.favicon.variant(resize: '244x104>')) %>
+ <%= f.field_container :favicon_image, class: ['form-group'] do %>
+ <% if @store.favicon_image.attached? && @store.favicon_image.variable? %>
+ <%= image_tag main_app.url_for(@store.favicon_image.variant(resize: '104x104')) %>
<% end %>
- <%= f.field_container :favicon, class: ['form-group'] do %>
- <%= f.label :favicon, Spree.t(:favicon) %><br>
- <%= f.file_field :favicon, accept: 'image/png, image/x-icon' %>
- <%= f.error_message_on :favicon %>
+ <%= f.field_container :favicon_image, class: ['form-group'] do %>
+ <%= f.label :favicon_image, Spree.t(:favicon) %><br>
+ <%= f.file_field :favicon_image, accept: 'image/png, image/x-icon' %>
+ <%= f.error_message_on :favicon_image %>
<% end %>
<% end %>
<%= f.field_container :name, class: ['form-group'] do %>
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 7bfad08180..61ace403d6 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -60,6 +60,10 @@ module Spree
end
end
+ def favicon_path
+ main_app.url_for(current_store.favicon)
+ end
+
def object
instance_variable_get('@' + controller_name.singularize)
end
diff --git a/core/app/models/spree/app_configuration.rb b/core/app/models/spree/app_configuration.rb
index 1029b3cf7f..64882ca503 100644
--- a/core/app/models/spree/app_configuration.rb
+++ b/core/app/models/spree/app_configuration.rb
@@ -47,6 +47,7 @@ module Spree
preference :disable_sku_validation, :boolean, default: false # when turned off disables the built-in SKU uniqueness validation
preference :expedited_exchanges, :boolean, default: false # NOTE this requires payment profiles to be supported on your gateway of choice as well as a delayed job handler to be configured with activejob. kicks off an exchange shipment upon return authorization save. charge customer if they do not return items within timely manner.
preference :expedited_exchanges_days_window, :integer, default: 14 # the amount of days the customer has to return their item after the expedited exchange is shipped in order to avoid being charged
+ preference :favicon, :string, default: 'favicon.ico'
preference :layout, :string, default: 'spree/layouts/spree_application'
preference :logo, :string, default: 'logo/spree_50.png'
preference :mailer_logo, :string, default: 'logo/spree_50.png'
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 0f0326ad53..0227ac747f 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -23,11 +23,11 @@ module Spree
has_one_attached :logo
has_one_attached :mailer_logo
- has_one_attached :favicon
+ has_one_attached :favicon_image
validates :mailer_logo, content_type: ['image/png', 'image/jpg', 'image/jpeg']
- validates :favicon, content_type: ['image/png', 'image/x-icon']
+ validates :favicon_image, content_type: ['image/png', 'image/x-icon', 'image/vnd.microsoft.icon']
before_save :ensure_default_exists_and_is_unique
before_save :ensure_supported_currencies, :ensure_supported_locales
@@ -93,6 +93,13 @@ module Spree
@checkout_zone_or_default ||= checkout_zone || Spree::Zone.default_checkout_zone
end
+ def favicon
+ return Config[:favicon] unless favicon_image.attached?
+ return favicon_image.variant(resize: '32x32') if favicon_image.variable?
+
+ favicon_image
+ end
+
private
def ensure_default_exists_and_is_unique
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 83bca3e1b8..ed2ca42362 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -898,6 +898,7 @@ en:
existing_shipments: Existing shipments
facebook: Facebook
failed_payment_attempts: Failed Payment Attempts
+ favicon: 'Favicon'
filename: Filename
fill_in_customer_info: Please fill in customer info
filter: Filter
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 985e6201e0..52e3ba1b43 100644
--- a/core/lib/spree/permitted_attributes.rb
+++ b/core/lib/spree/permitted_attributes.rb
@@ -101,7 +101,7 @@ module Spree
:customer_support_email, :facebook, :twitter, :instagram,
:description, :address, :contact_phone, :supported_locales,
:default_locale, :default_country_id, :supported_currencies,
- :new_order_notifications_email, :mailer_logo, :favicon, :checkout_zone_id, :seo_robots]
+ :new_order_notifications_email, :mailer_logo, :favicon_image, :checkout_zone_id, :seo_robots]
@@store_credit_attributes = %i[amount currency category_id memo]
diff --git a/frontend/app/views/spree/shared/_head.html.erb b/frontend/app/views/spree/shared/_head.html.erb
index 9034e4a802..b08fa67d5b 100644
--- a/frontend/app/views/spree/shared/_head.html.erb
+++ b/frontend/app/views/spree/shared/_head.html.erb
@@ -4,7 +4,7 @@
<%== meta_data_tags %>
<%== meta_robots %>
<%= canonical_tag(current_store.url) %>
-<%= favicon_link_tag 'favicon.ico' %>
+<%= favicon_link_tag(favicon_path) %>
<%= stylesheet_link_tag 'spree/frontend/all', media: 'screen', 'data-turbolinks-track': 'reload' %>
<%= csrf_meta_tags %>
<%= render 'spree/shared/paths' %>