mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
Sends confirmation email when Enterprise is created
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
.container#registration-finished
|
||||
.header
|
||||
%h2 Well done!
|
||||
%h5
|
||||
You have successfully completed the profile for
|
||||
%h5
|
||||
You have successfully completed the profile for
|
||||
%span.brick{"ng-show" => "enterprise.is_distributor"}
|
||||
{{ enterprise.name }}
|
||||
%span.turquoise{"ng-show" => "!enterprise.is_distributor" }
|
||||
@@ -10,10 +10,9 @@
|
||||
.content{ style: 'text-align: center'}
|
||||
%h3 Why not check it out on the Open Food Network?
|
||||
%a.button.primary{ type: "button", href: "/map" } Go to Map Page >
|
||||
|
||||
|
||||
%br
|
||||
%br
|
||||
|
||||
|
||||
%h3 Next step - add some products:
|
||||
%a.button.primary{ type: "button", href: "/admin/products/new" } Add a Product >
|
||||
|
||||
12
app/mailers/enterprise_mailer.rb
Normal file
12
app/mailers/enterprise_mailer.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class EnterpriseMailer < Spree::BaseMailer
|
||||
def creation_confirmation(enterprise)
|
||||
find_enterprise(enterprise)
|
||||
subject = "#{@enterprise.name} is now on #{Spree::Config[:site_name]}"
|
||||
mail(:to => @enterprise.owner.email, :from => from_address, :subject => subject)
|
||||
end
|
||||
|
||||
private
|
||||
def find_enterprise(enterprise)
|
||||
@enterprise = enterprise.is_a?(Enterprise) ? enterprise : Enterprise.find(enterprise)
|
||||
end
|
||||
end
|
||||
@@ -6,6 +6,8 @@ class Enterprise < ActiveRecord::Base
|
||||
|
||||
acts_as_gmappable :process_geocoding => false
|
||||
|
||||
after_create :send_creation_email
|
||||
|
||||
has_and_belongs_to_many :groups, class_name: 'EnterpriseGroup'
|
||||
has_many :producer_properties, foreign_key: 'producer_id'
|
||||
has_many :supplied_products, :class_name => 'Spree::Product', :foreign_key => 'supplier_id', :dependent => :destroy
|
||||
@@ -227,6 +229,10 @@ class Enterprise < ActiveRecord::Base
|
||||
|
||||
private
|
||||
|
||||
def send_creation_email
|
||||
EnterpriseMailer.creation_confirmation(self).deliver
|
||||
end
|
||||
|
||||
def strip_url(url)
|
||||
url.andand.sub /(https?:\/\/)?/, ''
|
||||
end
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
%h1
|
||||
= @enterprise.name + " has been created"
|
||||
|
||||
%h3
|
||||
Why not check it out on
|
||||
%a{ href: "#{map_url}" }
|
||||
= Spree::Config[:site_name] + "?"
|
||||
|
||||
If you have any questions, please get in touch with us at: hello@openfoodnetwork.org
|
||||
13
spec/mailers/enterprise_mailer_spec.rb
Normal file
13
spec/mailers/enterprise_mailer_spec.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe EnterpriseMailer do
|
||||
before do
|
||||
@enterprise = create(:enterprise)
|
||||
ActionMailer::Base.deliveries = []
|
||||
end
|
||||
|
||||
it "should send an email when given an enterprise" do
|
||||
EnterpriseMailer.creation_confirmation(@enterprise).deliver
|
||||
ActionMailer::Base.deliveries.count.should == 1
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user