spree_bronto 3.pre.0.pre.stable

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +8 -0
  5. data/LICENSE +26 -0
  6. data/README.md +73 -0
  7. data/Rakefile +21 -0
  8. data/app/assets/javascripts/spree/backend/spree_bronto.js +4 -0
  9. data/app/assets/javascripts/spree/frontend/bronto_list.js.coffee +8 -0
  10. data/app/assets/javascripts/spree/frontend/spree_bronto.js +2 -0
  11. data/app/assets/stylesheets/spree/backend/spree_bronto.css +4 -0
  12. data/app/assets/stylesheets/spree/frontend/spree_bronto.css +4 -0
  13. data/app/controllers/spree/admin/bronto_lists_controller.rb +24 -0
  14. data/app/controllers/spree/checkout_controller_decorator.rb +23 -0
  15. data/app/controllers/spree/home_controller_decorator.rb +120 -0
  16. data/app/controllers/spree/lists.rb +152 -0
  17. data/app/controllers/spree/orders_controller_decorator.rb +56 -0
  18. data/app/controllers/spree/users_controller_decorator.rb +27 -0
  19. data/app/mailers/spree/order_mailer/_order_cancel_html.html.erb +4 -0
  20. data/app/mailers/spree/order_mailer/_order_cancel_plain.erb +7 -0
  21. data/app/mailers/spree/order_mailer/_order_confirm_html.html.erb +5 -0
  22. data/app/mailers/spree/order_mailer/_order_confirm_plain.erb +7 -0
  23. data/app/mailers/spree/order_mailer/_order_details_html.html.erb +52 -0
  24. data/app/mailers/spree/order_mailer/_order_details_plain.erb +22 -0
  25. data/app/mailers/spree/order_mailer/_order_shipped_html.html.erb +20 -0
  26. data/app/mailers/spree/order_mailer/_order_shipped_plain.erb +21 -0
  27. data/app/mailers/spree/user_mailer/_password_reset_instructions.html.erb +9 -0
  28. data/app/mailers/spree/user_mailer_decorator.rb +13 -0
  29. data/app/models/spree/bronto_configuration.rb +12 -0
  30. data/app/models/spree/bronto_list.rb +20 -0
  31. data/app/models/spree/order_decorator.rb +30 -0
  32. data/app/models/spree/shipment_decorator.rb +18 -0
  33. data/app/models/spree/shipment_handler_decorator.rb +17 -0
  34. data/app/models/spree/store_decorator.rb +7 -0
  35. data/app/models/spree/user_decorator.rb +51 -0
  36. data/app/overrides/decorate_account_my_orders.rb +6 -0
  37. data/app/overrides/decorate_admin_configurations_index.rb +5 -0
  38. data/app/overrides/decorate_bronto_cart_recorvery.rb +6 -0
  39. data/app/overrides/decorate_bronto_list_subscribe.rb +6 -0
  40. data/app/views/spree/admin/bronto_lists/_autocomplete_form.js.erb +23 -0
  41. data/app/views/spree/admin/bronto_lists/_form.html.erb +49 -0
  42. data/app/views/spree/admin/bronto_lists/_get_lists.html.erb +1 -0
  43. data/app/views/spree/admin/bronto_lists/_get_lists.js.erb +1 -0
  44. data/app/views/spree/admin/bronto_lists/_retrieve_lists.js.erb +13 -0
  45. data/app/views/spree/admin/bronto_lists/edit.html.erb +11 -0
  46. data/app/views/spree/admin/bronto_lists/index.html.erb +38 -0
  47. data/app/views/spree/admin/bronto_lists/new.html.erb +11 -0
  48. data/app/views/spree/bronto_lists/_edit.html.erb +21 -0
  49. data/app/views/spree/bronto_lists/_form.html.erb +17 -0
  50. data/app/views/spree/bronto_lists/_signup.html.erb +13 -0
  51. data/app/views/spree/shared/_bronto_tags.html.erb +69 -0
  52. data/bin/rails +7 -0
  53. data/config/bronto.yml +39 -0
  54. data/config/locales/en.yml +27 -0
  55. data/config/routes.rb +19 -0
  56. data/db/migrate/20150427135748_spree_bronto_lists_users.rb +12 -0
  57. data/db/migrate/20150427135923_create_spree_bronto_lists.rb +16 -0
  58. data/lib/bronto_integration/bronto.rb +255 -0
  59. data/lib/bronto_integration/bronto_integration/communication.rb +83 -0
  60. data/lib/bronto_integration/bronto_integration/contact.rb +53 -0
  61. data/lib/bronto_integration/bronto_integration/order.rb +44 -0
  62. data/lib/bronto_integration/bronto_integration.rb +6 -0
  63. data/lib/delayed_send.rb +40 -0
  64. data/lib/delayed_simple_send.rb +17 -0
  65. data/lib/delayed_subscriber_add.rb +38 -0
  66. data/lib/delayed_subscriber_delete.rb +35 -0
  67. data/lib/delayed_subscriber_update.rb +38 -0
  68. data/lib/delayed_trigger.rb +17 -0
  69. data/lib/generators/spree_bronto/install/install_generator.rb +31 -0
  70. data/lib/spree_bronto/engine.rb +30 -0
  71. data/lib/spree_bronto/factories.rb +6 -0
  72. data/lib/spree_bronto.rb +2 -0
  73. data/spec/spec_helper.rb +87 -0
  74. data/spree_bronto.gemspec +32 -0
  75. metadata +258 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a3b281282ef7df4d0775cc2f3976816056a08299
4
+ data.tar.gz: c79c53d0d2365adb45ccaa4bdeb28f1303e1af75
5
+ SHA512:
6
+ metadata.gz: 3a7f38114418ee73de73409ab38df5912de2a61c1f0138be74801d4c0ce7abe92de5c6985dc66c66539d1189865f8e641f2563087185f16ff493bd113d84f772
7
+ data.tar.gz: 88c9f9674a8036d3bfc5ef1625cef6227ce3713d870ad7948a38f08bc1912e62e105b737bf5f98c375d74d07ac8174bcea9f4488ff9c2df84c8fb1b98e0373df
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ .sass-cache
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.swp
14
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'spree', github: 'spree/spree', branch: '3-0-stable'
4
+ gem 'savon', github: 'savonrb/savon'
5
+ # Provides basic authentication functionality for testing parts of your engine
6
+ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
7
+
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2015 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ SpreeBronto
2
+ ===========
3
+
4
+ Spree_bronto is one extension for spree to use Bronto mailing services and cart recovery tagging. Bronto API call code is basically one copy
5
+ from Wombat Bronto End_point.
6
+
7
+ This extension's older version is used in your Spree 0.11 web site.
8
+ This new spree 3.0 compatible version is brand new, please give any feedback to us: albertliu at naturalwellbeing.com
9
+
10
+
11
+ Yaml file to config your bronto acccount and email api id for order/shipment confirmation emails.
12
+ This extension support multi-domain, and can confiture at store level with identity with store code. if no store level config found, it fall to use the default
13
+
14
+ Put your own bronto.yml in your application's config folder. Its content should include following:
15
+ ##################
16
+ disable_cart_recovery: false
17
+ # if this option is false, the tagkey must be present in your yaml file
18
+
19
+ handle_asynchronously: true
20
+ # if this option is true, delayed_job must be configured.
21
+
22
+ default:
23
+ token: YOUR_BRONTO_TOKEN_TO_ACCESS_API
24
+ from_name: EMAIL_FROM NAME
25
+ tagkey: YOUR_BRONTO_CART_RECOVERY_KEY_IF_CART_RECOVERY_IS_ENABLED
26
+ order_shipped: EMAIL_API_ID_FOR_ORDER_SHIPPED_NOTIFICATION
27
+ order_received: EMAIL_API_ID_FOR_ORDER_CONFIRMATION
28
+ new_account: EMAIL_API_ID_FOR_ACCOUNT_CREATED
29
+ password_reset: EMAIL_API_ID_FOR_PASSWORD_RESET
30
+ order_canceled: EMAIL_API_ID_FOR_ORDER_CANCELED
31
+ #######################
32
+
33
+
34
+ Delayed_job is supposed to handle the asynch event here.
35
+
36
+ In bronto's configuration, you need create the email templates specified in bronto.yml. You also need create two content tags with name as
37
+ SENDTIME__CONTENT1 and SENDTIME__CONTENT2 .
38
+
39
+
40
+ Installation
41
+ ------------
42
+
43
+ Add spree_bronto to your Gemfile:
44
+
45
+ ```ruby
46
+ gem 'spree_bronto'
47
+ ```
48
+
49
+ Bundle your dependencies and run the installation generator:
50
+
51
+ ```shell
52
+ bundle
53
+ bundle exec rails g spree_bronto:install
54
+ ```
55
+
56
+ Testing
57
+ -------
58
+
59
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
60
+
61
+ ```shell
62
+ bundle
63
+ bundle exec rake
64
+ ```
65
+
66
+ When testing your applications integration with this extension you may use it's factories.
67
+ Simply add this require statement to your spec_helper:
68
+
69
+ ```ruby
70
+ require 'spree_bronto/factories'
71
+ ```
72
+
73
+ Copyright (c) 2015 Naturalwellbeing distribution, released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'spree_bronto'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
@@ -0,0 +1,4 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
3
+
4
+ Spree.routes.bronto_list = Spree.pathFor('admin/bronto_lists/get_list')
@@ -0,0 +1,8 @@
1
+ $(document).ready $('#retrieve_bronto_list').click(->
2
+ $.getScript '/admin/bronto_lists/get_lists?list_id=' + $('#bronto_list_list_id').val() + '&store_id=' + $('#bronto_list_store_id').val()
3
+ return
4
+ )
5
+ $(document).ready $('#bronto_list_store_id').change(->
6
+ $.getScript '/admin/bronto_lists/get_lists?list_id=' + $('#bronto_list_list_id').val() + '&store_id=' + $('#bronto_list_store_id').val()
7
+ return
8
+ )
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
@@ -0,0 +1,24 @@
1
+ class Spree::Admin::BrontoListsController < Spree::Admin::ResourceController
2
+ before_action :find_stores, only: [:edit, :new]
3
+
4
+ def get_lists
5
+ @lists = []
6
+ @list_id = params[:list_id] if params.key? :list_id
7
+ @store_id = params[:store_id] if params.key? :store_id
8
+ @site= Spree::Store.find(@store_id)
9
+ bronto=Bronto.new(Spree::BrontoConfiguration.account[@site.code]['token'])
10
+ et_lists=bronto.read_lists
11
+ #et_list = ET::List.new(Spree::Config.get(:exact_target_user), Spree::Config.get(:exact_target_password))
12
+ et_lists.each do |etl|
13
+ #list = et_list.retrieve_by_id etl[:id]
14
+ @lists << ["#{etl[:name]}", etl[:id]]
15
+ end
16
+ render :partial => "get_lists", :layout => false
17
+ end
18
+
19
+ private
20
+
21
+ def find_stores
22
+ @stores=Spree::Store.all
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ Spree::CheckoutController.class_eval do
2
+ include Spree::Lists
3
+ before_action :check_newsletter
4
+
5
+ def load_order_with_lock
6
+ @order = current_order(lock: true)
7
+ @bronto_lists=current_store.bronto_lists.select{|l| l.visible && !l.subscribe_all_new_users}
8
+ redirect_to spree.cart_path and return unless @order
9
+ end
10
+
11
+ private
12
+ def check_newsletter
13
+ if params['bronto_list']
14
+ params['bronto_list'].each do |k,v|
15
+ list=Spree::BrontoList.find(k)
16
+ if k && v && @order.email
17
+ subscribe_to_list(@order.email, list)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,120 @@
1
+ Spree::HomeController.class_eval do
2
+
3
+ def subscribenewsletter
4
+ name=params[:name] || ''
5
+ email=params[:email]
6
+ receipt=params[:receipt] || ''
7
+ subject=params[:subject] || 'Customer Record'
8
+ if receipt.length>0
9
+ external_key = Spree::BrontoConfiguration.account[current_store.code]["ET_simple_send"]
10
+ params.delete('action')
11
+ params.delete('receipt')
12
+ params.delete('authenticity_token')
13
+ params.delete('controller')
14
+ params.delete('subject')
15
+ params.delete('cc_receipt')
16
+ the_content=''
17
+ ks=[]
18
+ vs=[]
19
+ params.each do |k,v|
20
+ ks << k
21
+ vs << v
22
+ end
23
+ the_content = ks.join(',') + '<br/>' + vs.join(',')
24
+ et_a={:SENDTIME__CONTENT2 => the_content, :SENDTIME__CONTENT1 => subject}
25
+ #et_a={:SENDTIME__CONTENT2 => 'Name: ' + name +'<br/>Email: ' + email + '<br/>Address: ' + params[:address] + '<br/>City: ' + params[:city] + '<br/>State: ' + params[:state] +'<br/>Zip: ' + params[:zip] +'<br/>Phone: ' + params[:phone] +'<br/>Credentials: ' + params[:credentials]}
26
+ Delayed::Job.enqueue DelayedSimpleSend.new(current_store.code, receipt, external_key, et_a,'html')
27
+ cc_receipt= params[:cc_receipt] || ''
28
+ if cc_receipt.length>0
29
+ Delayed::Job.enqueue DelayedSimpleSend.new(current_store.code, cc_receipt, external_key, et_a,'html')
30
+ end
31
+ end
32
+ if email.length>0
33
+ if current_store.code == 'pwb'
34
+ title='Pets & Products Newsletter'
35
+ elsif current_store.code == 'he'
36
+ title='HairEssentials Products Newsletter'
37
+ else
38
+ title='Natural Products Newsletter'
39
+ end
40
+ campaign= Spree::BrontoList.find_by_title(title)
41
+ if !!campaign
42
+ Delayed::Job.enqueue DelayedSubscriberAdd.new(current_store.code, email, campaign, {:First_Name => name})
43
+ end
44
+ render :json => ({
45
+ :success => true,
46
+ :message => t( :subscription_sent )
47
+ }).to_json
48
+ else
49
+ render :json => ({
50
+ :success => false,
51
+ :message => t( :subscription_notsent )
52
+ }).to_json
53
+ end
54
+ #redirect_to "/meetexperts"
55
+ #render :js =>'alert("Our server temperarily busy, please try again later.")'
56
+
57
+ end
58
+
59
+ # sign up compaign flexible form, like the one for newsletter.
60
+ def subscribecampaign
61
+ name=params[:name] || ''
62
+ email=params[:email]
63
+ campaign_id=params[:campaign_id] || ''
64
+ if email.length>0
65
+ campaign=Spree::BrontoList.find_by_list_id(campaign_id)
66
+ if !!campaign
67
+ options=cookies[:campaign_options] || '{}'
68
+ options=Hash[JSON.parse(options).map{|(k,v)| [k.to_sym,v]}]
69
+ Rails.logger.info "find campaign_options cookie: #{cookies.inspect}"
70
+ Delayed::Job.enqueue DelayedSubscriberAdd.new(current_store.code, email, campaign, {:First_Name => name})
71
+ end
72
+
73
+ drop_email_key=params[:drop_email_key] || ''
74
+ unless drop_email_key.blank?
75
+ Delayed::Job.enqueue DelayedSimpleSend.new(current_store.code, email, drop_email_key, {},'html')
76
+ end
77
+ render :json => ({
78
+ :success => true,
79
+ :message => t( :subscription_sent )
80
+ }).to_json
81
+ else
82
+ render :json => ({
83
+ :success => false,
84
+ :message => t( :subscription_notsent )
85
+ }).to_json
86
+ end
87
+
88
+ end
89
+
90
+
91
+ # sign up compaign flexible form, like the one for newsletter.
92
+ def subscribecampaign_with_ops
93
+ email=params[:email]
94
+ campaign_id=params[:campaign_id] || ''
95
+ ops=params[:ops]
96
+ if email.length>0
97
+ campaign=Spree::BrontoList.find_by_list_id(campaign_id)
98
+ if !!campaign
99
+ Delayed::Job.enqueue DelayedSubscriberAdd.new(current_store.code, email, campaign,ops)
100
+ end
101
+
102
+ drop_email_key=params[:drop_email_key] || ''
103
+ unless drop_email_key.blank?
104
+ Delayed::Job.enqueue DelayedSimpleSend.new(current_store.code, email, drop_email_key, {},'html')
105
+ end
106
+
107
+ render :json => ({
108
+ :success => true,
109
+ :message => t( :subscription_sent )
110
+ }).to_json
111
+ else
112
+ render :json => ({
113
+ :success => false,
114
+ :message => t( :subscription_notsent )
115
+ }).to_json
116
+ end
117
+
118
+ end
119
+
120
+ end
@@ -0,0 +1,152 @@
1
+ module Spree
2
+ module Lists
3
+ extend ActiveSupport::Concern
4
+
5
+ def autosubscribe_list(store)
6
+ Spree::BrontoList.where(:store_id =>store.id,:subscribe_all_new_users =>true)
7
+ end
8
+
9
+ def create_subscriber(user)
10
+ if user.is_a? String
11
+ order = Spree::Order.find_by_email(user, :order => "updated_at desc")
12
+ store= current_order.store
13
+ list = autosubscribe_list(store) if checkout
14
+ else
15
+ store=current_store
16
+ list = autosubscribe_list(store)
17
+ end
18
+
19
+ subscribe_to_list(user, list) unless !list
20
+
21
+ # synchronize the subscription list from bronto this customer subscribed before registration
22
+ unless user.is_a? String
23
+ begin
24
+ user.reload
25
+ bronto=Bronto.new(Spree::BrontoConfiguration.account[store.code]['bronto_token'])
26
+ contact=bronto.read_contacts(user.email,true)
27
+ list_ids=contact[:list_ids]
28
+ if list_ids
29
+ unless list_ids.class == Array
30
+ list_ids=[list_ids]
31
+ end
32
+ list_ids.each do |l|
33
+ list=Spree::BrontoList.find_by_list_id(l)
34
+ if !!list && (!user.bronto_lists.map(&:list_id).include? l )
35
+ user.exact_target_subscriber_id = contact[:id] #seems we do not need this
36
+ user.bronto_lists << list
37
+ user.save!
38
+ end
39
+ end
40
+ end
41
+
42
+ rescue
43
+ # do nothing here at this moment
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ def subscribe_to_list(user, list)
50
+
51
+ order=current_order
52
+
53
+ pwb_cat=''
54
+ pwbCat = lambda{|order|
55
+ iscat=false
56
+ order.line_items.each do |item|
57
+ if item.variant.product.taxons.map{|t| t.id}.include?(3002)
58
+ iscat=true
59
+ end
60
+ end
61
+ if iscat
62
+ 'cat'
63
+ else
64
+ 'dog'
65
+ end
66
+ }
67
+ if order
68
+ #logger.debug 'call subscribe_to_list there is a order'
69
+ store=order.store
70
+ store_code=store.code
71
+ pwb_cat= (store_code=="pwb" ? pwbCat.call(order) : '')
72
+ else
73
+ store_code=current_store.code
74
+ pwb_cat=''
75
+ end
76
+ #logger.debug '-- found the pwb_cat: ' + pwb_cat
77
+ Delayed::Job.enqueue( DelayedSubscriberAdd.new(store_code, user, list, {:C_or_D => pwb_cat}), -20 )
78
+
79
+ unless user.is_a? String
80
+ user.bronto_lists << list
81
+ user.save!
82
+ end
83
+
84
+ end
85
+
86
+ def unsubscribe_from_list(user, list)
87
+
88
+ store = current_store
89
+ Delayed::Job.enqueue( DelayedSubscriberDelete.new(store.code, user, list), -20 )
90
+
91
+ unless user.is_a? String # update exact_target_lists
92
+ begin
93
+ list_del=user.bronto_lists.select{|l| l.id== list.id}
94
+ if list_del.length>0
95
+ user.bronto_lists.delete(list_del)
96
+ end
97
+ user.save!
98
+ rescue
99
+ #raise exception
100
+ end
101
+ end
102
+
103
+ end
104
+
105
+ #private
106
+ #CONTROLLER Actions
107
+ def get_bronto_lists
108
+ @bronto_lists = Spree::BrontoList.where(:visible => true)
109
+ end
110
+
111
+ def update_bronto_lists
112
+ return unless params.key? :bronto_list
113
+
114
+ unless @checkout.nil?
115
+ session[ :bronto_list ] = []
116
+ end
117
+
118
+ @user = @checkout.order.user if @user.nil? && !@checkout.nil?
119
+
120
+ params[:bronto_list].each do |id, do_subscribe|
121
+ do_subscribe = (do_subscribe == "true")
122
+ list = Spree::BrontoList.find(id)
123
+ if !@checkout.nil? && do_subscribe
124
+ session[ :bronto_list ] << id
125
+ end
126
+
127
+ if @user.nil? && !@checkout.nil? #guest checkout
128
+ if do_subscribe
129
+ #subscribe
130
+ subscribe_to_list(@checkout.email, list)
131
+ else
132
+ #unsubscribe
133
+ unsubscribe_from_list(@checkout.email, list)
134
+ end
135
+ else #normal checkout
136
+ if do_subscribe
137
+ #subscribe
138
+ unless @user.bronto_lists.include? list
139
+ subscribe_to_list(@user, list)
140
+ end
141
+ else
142
+ #unsubscribe
143
+ if @user.bronto_lists.include? list
144
+ unsubscribe_from_list(@user, list)
145
+ end
146
+ end
147
+ end
148
+ end
149
+
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,56 @@
1
+ Spree::OrdersController.class_eval do
2
+ include Spree::Lists
3
+
4
+ def subscribe
5
+ @order = Spree::Order.find_by_number!(params[:id])
6
+ list = Spree::BrontoList.find( params[ :list ] )
7
+ unless list.nil?
8
+ unless @order.user.nil?
9
+ dest = @order.user
10
+ else
11
+ dest = @order.email
12
+ end
13
+ unless dest.nil?
14
+ subscribe_to_list(dest, list)
15
+ respond_to do |format|
16
+ format.html {
17
+ flash[:notice] = Spree.t( :subscription_sent ) unless session[ :return_to ]
18
+ redirect_to checkout_state_path(@order.state)
19
+ }
20
+ format.js {
21
+ render :json => ({
22
+ :success => true,
23
+ :message => Spree.t( :subscription_sent )
24
+ }).to_json
25
+ }
26
+ end
27
+ else
28
+ respond_to do |format|
29
+ format.html {
30
+ flash[:error] = Spree.t( :subscription_notsent ) unless session[ :return_to ]
31
+ redirect_to checkout_state_path(@order.state)
32
+ }
33
+ format.js {
34
+ render :json => ({
35
+ :success => false,
36
+ :message => Spree.t( :subscription_notsent )
37
+ }).to_json
38
+ }
39
+ end
40
+ end
41
+ else
42
+ respond_to do |format|
43
+ format.html {
44
+ flash[:error] = Spree.t( :no_such_list ) unless session[ :return_to ]
45
+ redirect_to checkout_state_path(@order.state)
46
+ }
47
+ format.js {
48
+ render :json => ({
49
+ :success => false,
50
+ :message => Spree.t( :no_such_list )
51
+ }).to_json
52
+ }
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,27 @@
1
+ Spree::UsersController.class_eval do
2
+ include Spree::Lists
3
+
4
+ before_action :load_bronto_lists
5
+ before_action :check_newsletter
6
+
7
+ private
8
+ def load_bronto_lists
9
+ @bronto_lists=current_store.bronto_lists
10
+ end
11
+
12
+ def check_newsletter
13
+ if params['user'] && params['user']['bronto_list_attributes']
14
+ params['user']['bronto_list_attributes'].each do|k,v|
15
+ list=Spree::BrontoList.find(k)
16
+ if k && @user && v=="true"
17
+ subscribe_to_list(@user, list)
18
+ end
19
+
20
+ if k && @user && v=="false"
21
+ unsubscribe_from_list(@user, list)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ <p>This email is to inform you that your order has been <strong>cancelled</strong> on <%= Time.now.strftime("%B %d %Y at %I:%M %p") %>.</p>
2
+ <p>Your order number is <strong class="pink"><%= order.number %></strong> Please keep it for reference if you speak to a customer service representative.</p>
3
+ <p>Your <%= order.store.name %> order included the following item(s):</p>
4
+ <%= render "order_mailer/order_details_html", :order => order %>
@@ -0,0 +1,7 @@
1
+ This email is to inform you that your order has been CANCELLED on <%= Time.now.strftime("%B %d %Y at %I:%M %p") %>.
2
+
3
+ Your order number is <%= order.number %> Please keep it for reference if you speak to a customer service representative.
4
+
5
+ Your <%= order.store.name %> order included the following item(s):
6
+
7
+ <%= render "order_mailer/order_details_plain", :order => order %>
@@ -0,0 +1,5 @@
1
+ <p>Here are the details of your order received on <%= order.completed_at.strftime("%B %d %Y at %I:%M %p") %>.</p>
2
+ <p>Your order number is <strong class="pink"><%= order.number %></strong> Please keep it for reference if you speak to a customer service representative.</p>
3
+
4
+ <p>Your <%= order.store.name %> order includes the following item(s):</p>
5
+ <%= render "order_mailer/order_details_html", :order => order %>
@@ -0,0 +1,7 @@
1
+ Here are the details of your order received on <%= order.completed_at.strftime("%B %d %Y at %I:%M %p") %>.
2
+
3
+ Your order number is <%= order.number %> Please keep it for reference if you speak to a customer service representative.
4
+
5
+ Your <%= order.store.name %> order includes the following item(s):
6
+
7
+ <%= render "order_mailer/order_details_plain", :order => order %>