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.

Draft commit with model and form for the favicon

Damian Kaczmarczyk2378b8e86db3
diff --git a/backend/app/views/spree/admin/stores/_form.html.erb b/backend/app/views/spree/admin/stores/_form.html.erb
index b885d8f938..dea55ca5b8 100644
--- a/backend/app/views/spree/admin/stores/_form.html.erb
+++ b/backend/app/views/spree/admin/stores/_form.html.erb
@@ -29,6 +29,16 @@
<%= 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>')) %>
+ <% 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 %>
+ <% end %>
+ <% end %>
<%= f.field_container :name, class: ['form-group'] do %>
<%= f.label :name, raw(Spree.t(:name) + required_span_tag) %>
<%= f.text_field :name, class: 'form-control', required: true %>
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index a49e63b320..0f0326ad53 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -23,9 +23,12 @@ module Spree
has_one_attached :logo
has_one_attached :mailer_logo
+ has_one_attached :favicon
validates :mailer_logo, content_type: ['image/png', 'image/jpg', 'image/jpeg']
+ validates :favicon, content_type: ['image/png', 'image/x-icon']
+
before_save :ensure_default_exists_and_is_unique
before_save :ensure_supported_currencies, :ensure_supported_locales
before_destroy :validate_not_default
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 8f355e3401..985e6201e0 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, :checkout_zone_id, :seo_robots]
+ :new_order_notifications_email, :mailer_logo, :favicon, :checkout_zone_id, :seo_robots]
@@store_credit_attributes = %i[amount currency category_id memo]