Skip to content

Commit

Permalink
[SDP-314] Adds user currently chosen store info for mailers
Browse files Browse the repository at this point in the history
  • Loading branch information
aplegatt committed Jul 3, 2020
1 parent 48602a2 commit 169dac4
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 14 deletions.
14 changes: 10 additions & 4 deletions app/mailers/spree/user_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
module Spree
class UserMailer < BaseMailer
def reset_password_instructions(user, token, *_args)
@edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: Spree::Store.current.url)
@current_store = user&.current_store || Spree::Store.current
@locale = user&.current_store&.default_locale
I18n.locale = @locale if @locale.present?
@edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: @current_store.url)

mail to: user.email, from: from_address, subject: Spree::Store.current.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])
mail to: user.email, from: from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])
end

def confirmation_instructions(user, token, _opts = {})
@confirmation_url = spree.spree_user_confirmation_url(confirmation_token: token, host: Spree::Store.current.url)
@current_store = user&.current_store || Spree::Store.current
@locale = user&.current_store&.default_locale
I18n.locale = @locale if @locale.present?
@confirmation_url = spree.spree_user_confirmation_url(confirmation_token: token, host: @current_store.url)
@email = user.email

mail to: user.email, from: from_address, subject: Spree::Store.current.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions])
mail to: user.email, from: from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions])
end
end
end
2 changes: 2 additions & 0 deletions app/models/spree/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class User < Spree::Base

scope :admin, -> { includes(:spree_roles).where("#{roles_table_name}.name" => "admin") }

belongs_to :current_store, foreign_key: :store_id, class_name: 'Spree::Store', optional: true

def self.admin_created?
User.admin.exists?
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Welcome <%= @email %>!
<%= Spree.t('confirmation_instructions.welcome', email: @email) %>

You can confirm your account email through the url below:
<%= Spree.t('confirmation_instructions.confirm') %>

<%= @confirmation_url %>
<%= @confirmation_url %>
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
A request to reset your password has been made.
If you did not make this request, simply ignore this email.

If you did make this request just click the link below:
<%= Spree.t('user_mailer.reset_password_instructions.instructions_1') %>

<%= @edit_password_reset_url %>

If the above URL does not work try copying and pasting it into your browser.
If you continue to have problems please feel free to contact us.

<%= Spree.t('user_mailer.reset_password_instructions.instructions_2') %>
7 changes: 7 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ de:
change_your_password: Kennwort zurücksetzen
store_credits:
credit_balance: Saldo des Guthabens
user_mailer:
reset_password_instructions:
instructions_1: "Es wurde eine Anfrage zum Zurücksetzen Ihres Passworts gestellt.\nWenn Sie diese Anfrage nicht gestellt haben, ignorieren Sie diese E-Mail.\n\nWenn Sie diese Anfrage gestellt haben, klicken Sie bitte auf den folgenden Link:"
instructions_2: "Falls die obige URL nicht funktioniert, bitte URL kopieren und in Ihren Browser einfügen\nWenn Sie weiterhin Probleme haben, können Sie sich gerne an uns wenden."
confirmation_instructions:
welcome: "Schön, dass Sie hier sind %{email}"
confirm: "Sie können Ihre Konto-E-Mail-Adresse über die folgende URL bestätigen:"
devise:
confirmations:
confirmed: Ihr Konto wurde erfolgreich aktiviert.
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ en:
change_your_password: "Change your password"
store_credits:
credit_balance: Store Credit Balance
user_mailer:
reset_password_instructions:
instructions_1: "A request to reset your password has been made.\nIf you did not make this request, simply ignore this email.\n\nIf you did make this request just click the link below:"
instructions_2: "If the above URL does not work try copying and pasting it into your browser.\nIf you continue to have problems please feel free to contact us."
confirmation_instructions:
welcome: "Welcome %{email}!"
confirm: "You can confirm your account email through the url below:"
devise:
confirmations:
confirmed: Your account was successfully confirmed. You are now signed in.
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20200702073908_add_store_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddStoreToUser < ActiveRecord::Migration[6.0]
def change
unless column_exists?(:spree_users, :store_id)
add_column :spree_users, :store_id, :integer
end
end
end
22 changes: 22 additions & 0 deletions lib/spree/core/controller_helpers/store_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Spree
module Core
module ControllerHelpers
module StoreDecorator
def self.prepended(base)
base.included do
before_action :set_user_current_store
end
end

def set_user_current_store
return if try_spree_current_user.nil?

try_spree_current_user.current_store = current_store
try_spree_current_user.save
end
end
end
end
end

Spree::Core::ControllerHelpers::Store.prepend Spree::Core::ControllerHelpers::StoreDecorator

0 comments on commit 169dac4

Please sign in to comment.