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.

[EN-499] Adds uploading of mailer logo to store form

Robert Nowakowski3a4acaa8b769
diff --git a/backend/app/views/spree/admin/stores/_form.html.erb b/backend/app/views/spree/admin/stores/_form.html.erb
index e00bc0304b..ea02284156 100644
--- a/backend/app/views/spree/admin/stores/_form.html.erb
+++ b/backend/app/views/spree/admin/stores/_form.html.erb
@@ -19,6 +19,16 @@
<%= f.error_message_on :logo %>
<% end %>
<% end %>
+ <%= f.field_container :mailer_logo, class: ['form-group'] do %>
+ <% if @store.mailer_logo.attached? %>
+ <%= image_tag main_app.url_for(@store.mailer_logo.variant(resize: '244x104>')) %>
+ <% end %>
+ <%= f.field_container :mailer_logo, class: ['form-group'] do %>
+ <%= f.label :mailer_logo, Spree.t(:mailer_logo) %><br />
+ <%= f.file_field :mailer_logo, accept: 'image/png, image/jpeg' %>
+ <%= f.error_message_on :mailer_logo %>
+ <% 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/helpers/spree/mail_helper.rb b/core/app/helpers/spree/mail_helper.rb
index 4293404560..02333a5c7c 100644
--- a/core/app/helpers/spree/mail_helper.rb
+++ b/core/app/helpers/spree/mail_helper.rb
@@ -12,7 +12,7 @@ module Spree
end
def store_logo
- @order&.store&.logo || current_store.logo
+ @order&.store&.mailer_logo || @order&.store&.logo || current_store.mailer_logo || current_store.logo
end
def default_logo
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index b2afab1ce3..6f81fde862 100644
--- a/core/app/models/spree/store.rb
+++ b/core/app/models/spree/store.rb
@@ -18,6 +18,7 @@ module Spree
end
has_one_attached :logo
+ has_one_attached :mailer_logo
before_save :ensure_default_exists_and_is_unique
before_destroy :validate_not_default
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index d29feaaba3..001c499d9b 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -1036,6 +1036,7 @@ en:
make_refund: Make refund
make_sure_the_above_reimbursement_amount_is_correct: Make sure the above reimbursement amount is correct
mail_from_address: Mail from address
+ mailer_logo: Mailer logo (JPG or PNG images only)
manage_promotion_categories: Manage Promotion Categories
manual_intervention_required: Manual intervention required
manage_variants: Manage Variants
diff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rb
index 8bbb12db25..63855a98a6 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_email, :contact_phone,
:default_locale, :default_country_id, :supported_currencies,
- :new_order_notifications_email]
+ :new_order_notifications_email, :mailer_logo]
@@store_credit_attributes = %i[amount currency category_id memo]
diff --git a/core/spec/helpers/mail_helper_spec.rb b/core/spec/helpers/mail_helper_spec.rb
index b0d9bb96a8..d9f1a22e8c 100644
--- a/core/spec/helpers/mail_helper_spec.rb
+++ b/core/spec/helpers/mail_helper_spec.rb
@@ -67,12 +67,12 @@ module Spree
let(:logo_image) { File.open(File.expand_path('../../app/assets/images/logo/spree_50.png', __dir__)) }
before do
- store.logo.attach(io: logo_image, filename: 'spree_50.png', content_type: 'image/png')
+ store.mailer_logo.attach(io: logo_image, filename: 'spree_50.png', content_type: 'image/png')
@order = create(:order, store: store)
end
it 'shows logo attached to orders store' do
- expect(subject).to include(store.logo.attachment.filename.to_s)
+ expect(subject).to include(store.mailer_logo.attachment.filename.to_s)
end
end
@@ -80,11 +80,11 @@ module Spree
let(:logo_image) { File.open(File.expand_path('../../app/assets/images/noimage/mini.png', __dir__)) }
before do
- store.logo.attach(io: logo_image, filename: 'mini.png', content_type: 'image/png')
+ store.mailer_logo.attach(io: logo_image, filename: 'mini.png', content_type: 'image/png')
end
it 'shows logo attached to current store' do
- expect(subject).to include(store.logo.attachment.filename.to_s)
+ expect(subject).to include(store.mailer_logo.attachment.filename.to_s)
end
end
end