workarea-emarsys 1.0.2

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 (114) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.gitignore +22 -0
  7. data/CHANGELOG.md +28 -0
  8. data/CODE_OF_CONDUCT.md +3 -0
  9. data/CONTRIBUTING.md +3 -0
  10. data/Gemfile +12 -0
  11. data/LICENSE +52 -0
  12. data/LICENSE.md +3 -0
  13. data/README.md +93 -0
  14. data/Rakefile +60 -0
  15. data/app/assets/images/emarsys/.keep +0 -0
  16. data/app/assets/javascripts/emarsys/.keep +0 -0
  17. data/app/assets/javascripts/workarea/storefront/emarsys/modules/web_extend_adapter.js +128 -0
  18. data/app/assets/stylesheets/emarsys/.keep +0 -0
  19. data/app/controllers/.keep +0 -0
  20. data/app/controllers/workarea/admin/configurations_controller.rb +33 -0
  21. data/app/controllers/workarea/storefront/email_signups_controller.decorator +16 -0
  22. data/app/controllers/workarea/storefront/users/addresses_controller.decorator +13 -0
  23. data/app/helpers/.keep +0 -0
  24. data/app/helpers/workarea/storefront/emarsys_analytics_helper.rb +13 -0
  25. data/app/lib/workarea/emarsys/bogus_gateway.rb +36 -0
  26. data/app/lib/workarea/emarsys/gateway.rb +94 -0
  27. data/app/lib/workarea/emarsys/response.rb +18 -0
  28. data/app/lib/workarea/emarsys/sales_data_bogus_gateway.rb +29 -0
  29. data/app/lib/workarea/emarsys/sales_data_gateway.rb +51 -0
  30. data/app/models/emarsys/configuration.rb +16 -0
  31. data/app/models/emarsys/country.rb +220 -0
  32. data/app/models/workarea/email/signup.decorator +8 -0
  33. data/app/models/workarea/order.decorator +8 -0
  34. data/app/models/workarea/user.decorator +8 -0
  35. data/app/services/emarsys/contact/order.rb +31 -0
  36. data/app/services/emarsys/contact/user.rb +25 -0
  37. data/app/services/emarsys/contact.rb +55 -0
  38. data/app/view_models/workarea/admin/emarsys_configuration_view_model.rb +20 -0
  39. data/app/views/workarea/admin/emarsys/configurations/edit.html.haml +68 -0
  40. data/app/views/workarea/admin/shared/_emarsys_configuration_link.html.haml +1 -0
  41. data/app/views/workarea/storefront/_emarsys_tracking.html.haml +11 -0
  42. data/app/views/workarea/storefront/emarsys/_current_user_emarsys_cart.json.jbuilder +6 -0
  43. data/app/workers/workarea/emarsys/save_email_signup.rb +40 -0
  44. data/app/workers/workarea/emarsys/save_order.rb +32 -0
  45. data/app/workers/workarea/emarsys/save_user.rb +44 -0
  46. data/app/workers/workarea/emarsys/sync_orders.rb +50 -0
  47. data/bin/rails +20 -0
  48. data/config/initializers/appends.rb +19 -0
  49. data/config/initializers/scheduled_jobs.rb +6 -0
  50. data/config/initializers/workarea.rb +16 -0
  51. data/config/locales/en.yml +28 -0
  52. data/config/routes.rb +7 -0
  53. data/lib/workarea/emarsys/engine.rb +12 -0
  54. data/lib/workarea/emarsys/version.rb +5 -0
  55. data/lib/workarea/emarsys.rb +59 -0
  56. data/test/dummy/Rakefile +6 -0
  57. data/test/dummy/app/assets/config/manifest.js +4 -0
  58. data/test/dummy/app/assets/images/.keep +0 -0
  59. data/test/dummy/app/assets/javascripts/application.js +13 -0
  60. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  61. data/test/dummy/app/controllers/application_controller.rb +3 -0
  62. data/test/dummy/app/controllers/concerns/.keep +0 -0
  63. data/test/dummy/app/helpers/application_helper.rb +2 -0
  64. data/test/dummy/app/jobs/application_job.rb +2 -0
  65. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  66. data/test/dummy/app/models/concerns/.keep +0 -0
  67. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  68. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  69. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  70. data/test/dummy/bin/bundle +3 -0
  71. data/test/dummy/bin/rails +4 -0
  72. data/test/dummy/bin/rake +4 -0
  73. data/test/dummy/bin/setup +30 -0
  74. data/test/dummy/bin/update +26 -0
  75. data/test/dummy/bin/yarn +11 -0
  76. data/test/dummy/config/application.rb +30 -0
  77. data/test/dummy/config/boot.rb +5 -0
  78. data/test/dummy/config/cable.yml +10 -0
  79. data/test/dummy/config/environment.rb +5 -0
  80. data/test/dummy/config/environments/development.rb +51 -0
  81. data/test/dummy/config/environments/production.rb +88 -0
  82. data/test/dummy/config/environments/test.rb +44 -0
  83. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  84. data/test/dummy/config/initializers/assets.rb +14 -0
  85. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  86. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  87. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  88. data/test/dummy/config/initializers/inflections.rb +16 -0
  89. data/test/dummy/config/initializers/mime_types.rb +4 -0
  90. data/test/dummy/config/initializers/workarea.rb +5 -0
  91. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  92. data/test/dummy/config/locales/en.yml +33 -0
  93. data/test/dummy/config/puma.rb +56 -0
  94. data/test/dummy/config/routes.rb +5 -0
  95. data/test/dummy/config/secrets.yml +32 -0
  96. data/test/dummy/config/spring.rb +6 -0
  97. data/test/dummy/config.ru +5 -0
  98. data/test/dummy/db/seeds.rb +2 -0
  99. data/test/dummy/lib/assets/.keep +0 -0
  100. data/test/dummy/log/.keep +0 -0
  101. data/test/integration/workarea/admin/emarsys_configuration_integration_test.rb +25 -0
  102. data/test/lib/workarea/emarsys/gateway_test.rb +26 -0
  103. data/test/services/emarsys/contact_test.rb +44 -0
  104. data/test/support/workarea/emarsys_api_config.rb +19 -0
  105. data/test/system/workarea/storefront/emarsys_tracking_system_test.rb +25 -0
  106. data/test/teaspoon_env.rb +6 -0
  107. data/test/test_helper.rb +10 -0
  108. data/test/vcr_cassettes/emarsys/add_contact.yml +67 -0
  109. data/test/vcr_cassettes/emarsys/get_contact.yml +129 -0
  110. data/test/vcr_cassettes/emarsys/sales/send_data.yml +42 -0
  111. data/test/workers/workarea/emarsys/save_user_test.rb +30 -0
  112. data/test/workers/workarea/emarsys/sync_orders_test.rb +38 -0
  113. data/workarea-emarsys.gemspec +24 -0
  114. metadata +211 -0
@@ -0,0 +1,94 @@
1
+ module Workarea
2
+ module Emarsys
3
+ class Gateway
4
+ attr_reader :secret_key, :customer_id, :options
5
+
6
+ def initialize(secret_key, customer_id, options = {})
7
+ @secret_key = secret_key
8
+ @customer_id = customer_id
9
+ @options = options
10
+ end
11
+
12
+ def create_contact(attrs)
13
+ base_uri = "/api/v2/internal/#{customer_id}/contact/"
14
+ params = { create_if_not_exists: 1 }
15
+ query_values = "?" + params.to_query
16
+
17
+ path = base_uri + query_values
18
+
19
+ request_data = sign_request('put', path, attrs.to_json)
20
+
21
+ response = connection.put do |req|
22
+ req.url path
23
+ req.params = params
24
+ req.body = attrs.to_json
25
+
26
+ request_data[:headers].each do |k, v|
27
+ req.headers[k] = v
28
+ end
29
+ end
30
+
31
+ Response.new(response)
32
+ end
33
+
34
+ private
35
+
36
+ def connection
37
+ request_timeouts = {
38
+ timeout: Workarea::Emarsys.config.api_timeout,
39
+ open_timeout: Workarea::Emarsys.config.open_timeout
40
+ }
41
+
42
+ Faraday.new(url: rest_endpoint, request: request_timeouts)
43
+ end
44
+
45
+ def sign_request(method, path, body = nil)
46
+ escher = Escher::Auth.new('eu/suite/ems_request', escher_options)
47
+
48
+ request_data = {
49
+ method: method.upcase,
50
+ uri: path,
51
+ body: body,
52
+ headers: [['Content-Type', 'application/json'], ['host', host]]
53
+ }
54
+
55
+ escher.sign!(request_data, { api_key_id: escher_key, api_secret: secret_key })
56
+
57
+ request_data
58
+ end
59
+
60
+ def escher_options
61
+ {
62
+ algo_prefix: 'EMS',
63
+ vendor_key: 'EMS',
64
+ auth_header_name: 'X-Ems-Auth',
65
+ date_header_name: 'X-Ems-Date'
66
+ }
67
+ end
68
+
69
+ def escher_key
70
+ Workarea.config.emarsys.escher_key
71
+ end
72
+
73
+ def rest_endpoint
74
+ "https://#{host}"
75
+ end
76
+
77
+ def host
78
+ if test?
79
+ "api-proxy.s.emarsys.com"
80
+ else
81
+ "api.emarsys.net"
82
+ end
83
+ end
84
+
85
+ def uri_base
86
+ "/api/v2/internal/#{customer_id}/"
87
+ end
88
+
89
+ def test?
90
+ (options.has_key?(:test) ? options[:test] : true)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,18 @@
1
+ module Workarea
2
+ module Emarsys
3
+ class Response
4
+ def initialize(response)
5
+ @response = response
6
+ end
7
+
8
+ def success?
9
+ @response.success?
10
+ end
11
+
12
+ def body
13
+ return unless @response.body
14
+ @body ||= JSON.parse(@response.body)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,29 @@
1
+ module Workarea
2
+ module Emarsys
3
+ class SalesDataBogusGateway
4
+
5
+ attr_reader :options
6
+
7
+ def initialize(options = {})
8
+ @options = options
9
+ end
10
+
11
+ def send_file(file)
12
+ Response.new(response)
13
+ end
14
+
15
+ private
16
+
17
+ def response
18
+ response = Faraday.new do |builder|
19
+ builder.adapter :test do |stub|
20
+ stub.get('/rest/bogus.json') { |env| [ 200, {}, nil ] }
21
+ end
22
+ end
23
+ r = response.get('/rest/bogus.json')
24
+ Response.new(r)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,51 @@
1
+ module Workarea
2
+ module Emarsys
3
+ class SalesDataGateway
4
+ attr_reader :secret_key, :options
5
+
6
+ def initialize(secret_key, options = {})
7
+ @secret_key = secret_key
8
+ @options = options
9
+ end
10
+
11
+ def send_file(file)
12
+ path = "/hapi/merchant/#{merchant_id}/sales-data/api"
13
+
14
+ response = connection.post do |req|
15
+ req.url path
16
+ req.body = File.read(file)
17
+ end
18
+ Response.new(response)
19
+ end
20
+
21
+ private
22
+
23
+ def connection
24
+ headers = {
25
+ 'Content-Type' => 'text/csv',
26
+ 'Accept' => 'text/plain',
27
+ 'Authorization' => "Bearer #{secret_key}"
28
+ }
29
+
30
+ request_timeouts = {
31
+ timeout: Workarea::Emarsys.config.api_timeout,
32
+ open_timeout: Workarea::Emarsys.config.open_timeout
33
+ }
34
+
35
+ Faraday.new(url: rest_endpoint, headers: headers, request: request_timeouts) do |con|
36
+ con.request :multipart
37
+ con.request :url_encoded
38
+ con.adapter :net_http
39
+ end
40
+ end
41
+
42
+ def rest_endpoint
43
+ "https://admin.scarabresearch.com"
44
+ end
45
+
46
+ def merchant_id
47
+ options[:merchant_id]
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,16 @@
1
+ module Workarea
2
+ module Emarsys
3
+ class Configuration
4
+ include ApplicationDocument
5
+
6
+ field :merchant_id, type: String
7
+ field :customer_id, type: String
8
+
9
+ field :production, type: Boolean, default: false
10
+
11
+ def self.current
12
+ first || new
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,220 @@
1
+ module Emarsys
2
+ class Country
3
+ def find_code(country)
4
+ codes[country.optionize.to_sym] || nil
5
+ end
6
+
7
+ # each country and their corresponding
8
+ # integer value in the emarsys db
9
+ def codes
10
+ {
11
+ afghanistan: 1,
12
+ albania: 2,
13
+ algeria: 3,
14
+ andorra: 4,
15
+ angola: 5,
16
+ antigua_and_barbuda: 6,
17
+ argentina: 7,
18
+ armenia: 8,
19
+ australia: 9,
20
+ austria: 10,
21
+ azerbaijan: 11,
22
+ bahamas: 12,
23
+ bahrain: 13,
24
+ bangladesh: 14,
25
+ barbados: 15,
26
+ belarus: 16,
27
+ belgium: 17,
28
+ belize: 18,
29
+ benin: 19,
30
+ bhutan: 20,
31
+ bolivia: 21,
32
+ bosnia_and_herzegovina: 22,
33
+ botswana: 23,
34
+ brazil: 24,
35
+ brunei_darussalam: 25,
36
+ bulgaria: 26,
37
+ burkina_faso: 27,
38
+ burma: 28,
39
+ burundi: 29,
40
+ cambodia: 30,
41
+ cameroon: 31,
42
+ canada: 32,
43
+ cape_verde: 33,
44
+ central_african_republic: 34,
45
+ chad: 35,
46
+ chile: 36,
47
+ china: 37,
48
+ colombia: 38,
49
+ comoros: 39,
50
+ congo: 40,
51
+ congo_democratic_republic_of_the: 41,
52
+ costa_rica: 42,
53
+ cote_d_ivoire: 43,
54
+ croatia: 44,
55
+ cuba: 45,
56
+ cyprus: 46,
57
+ czech_republic: 47,
58
+ denmark: 48,
59
+ djibouti: 49,
60
+ dominica: 50,
61
+ dominican_republic: 51,
62
+ ecuador: 52,
63
+ egypt: 53,
64
+ el_salvador: 54,
65
+ equatorial_guinea: 55,
66
+ eritrea: 56,
67
+ estonia: 57,
68
+ ethiopia: 58,
69
+ fiji: 59,
70
+ finland: 60,
71
+ france: 61,
72
+ gabon: 62,
73
+ gambia_the: 63,
74
+ georgia: 64,
75
+ germany: 65,
76
+ ghana: 66,
77
+ greece: 67,
78
+ grenada: 68,
79
+ guatemala: 69,
80
+ guinea: 70,
81
+ guinea_bissau: 71,
82
+ guyana: 72,
83
+ haiti: 73,
84
+ honduras: 74,
85
+ hungary: 75,
86
+ iceland: 76,
87
+ india: 77,
88
+ indonesia: 78,
89
+ iran: 79,
90
+ iraq: 80,
91
+ ireland: 81,
92
+ israel: 82,
93
+ italy: 83,
94
+ jamaica: 84,
95
+ japan: 85,
96
+ jordan: 86,
97
+ kazakhstan: 87,
98
+ kenya: 88,
99
+ kiribati: 89,
100
+ korea_north: 90,
101
+ korea_south: 91,
102
+ kuwait: 92,
103
+ kyrgyzstan: 93,
104
+ laos: 94,
105
+ latvia: 95,
106
+ lebanon: 96,
107
+ lesotho: 97,
108
+ liberia: 98,
109
+ libya: 99,
110
+ liechtenstein: 100,
111
+ lithuania: 101,
112
+ luxembourg: 102,
113
+ macedonia: 103,
114
+ madagascar: 104,
115
+ malawi: 105,
116
+ malaysia: 106,
117
+ maldives: 107,
118
+ mali: 108,
119
+ malta: 109,
120
+ marshall_islands: 110,
121
+ mauritania: 111,
122
+ mauritius: 112,
123
+ mexico: 113,
124
+ micronesia: 114,
125
+ moldova: 115,
126
+ monaco: 116,
127
+ mongolia: 117,
128
+ morocco: 118,
129
+ mozambique: 119,
130
+ myanmar: 120,
131
+ namibia: 121,
132
+ nauru: 122,
133
+ nepal: 123,
134
+ the_netherlands: 124,
135
+ new_zealand: 125,
136
+ nicaragua: 126,
137
+ niger: 127,
138
+ nigeria: 128,
139
+ norway: 129,
140
+ oman: 130,
141
+ pakistan: 131,
142
+ palau: 132,
143
+ panama: 134,
144
+ papua_new_guinea: 135,
145
+ paraguay: 136,
146
+ peru: 137,
147
+ philippines: 138,
148
+ poland: 139,
149
+ portugal: 140,
150
+ qatar: 141,
151
+ romania: 142,
152
+ russia: 143,
153
+ rwanda: 144,
154
+ st_kitts_and_nevis: 145,
155
+ st_lucia: 146,
156
+ st_vincent_and_the_grenadines: 147,
157
+ samoa: 148,
158
+ san_marino: 149,
159
+ são_tomé_and_príncipe: 150,
160
+ saudi_arabia: 151,
161
+ senegal: 152,
162
+ serbia: 153,
163
+ seychelles: 154,
164
+ sierra_leone: 155,
165
+ singapore: 156,
166
+ slovakia: 157,
167
+ slovenia: 158,
168
+ solomon_islands: 159,
169
+ somalia: 160,
170
+ south_africa: 161,
171
+ spain: 162,
172
+ sri_lanka: 163,
173
+ sudan: 164,
174
+ suriname: 165,
175
+ swaziland: 166,
176
+ sweden: 167,
177
+ switzerland: 168,
178
+ syria: 169,
179
+ taiwan: 170,
180
+ tajikistan: 171,
181
+ tanzania: 172,
182
+ thailand: 173,
183
+ togo: 174,
184
+ tonga: 175,
185
+ trinidad_and_tobago: 176,
186
+ tunisia: 177,
187
+ turkey: 178,
188
+ turkmenistan: 179,
189
+ tuvalu: 180,
190
+ uganda: 181,
191
+ ukraine: 182,
192
+ united_arab_emirates: 183,
193
+ united_kingdom: 184,
194
+ united_states_of_america: 185,
195
+ uruguay: 186,
196
+ uzbekistan: 187,
197
+ vanuatu: 188,
198
+ vatican_city: 189,
199
+ venezuela: 190,
200
+ vietnam: 191,
201
+ western_sahara: 192,
202
+ yemen: 193,
203
+ yugoslavia: 194,
204
+ zaire: 195,
205
+ zambia: 196,
206
+ zimbabwe: 197,
207
+ greenland: 198,
208
+ virgin_islands: 199,
209
+ canary_islands: 201,
210
+ montenegro: 202,
211
+ gibraltar: 203,
212
+ netherlands_antilles: 204,
213
+ hong_kong: 205,
214
+ macau: 206,
215
+ east_timor: 258,
216
+ kosovo: 259
217
+ }
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,8 @@
1
+ module Workarea
2
+ decorate Email::Signup, with: :emarsys do
3
+ decorated do
4
+ field :emarsys_exported_at, type: Time
5
+ field :emarsys_external_id, type: String
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Workarea
2
+ decorate Order, with: :emarsys do
3
+ decorated do
4
+ scope :emarsys_exportable,
5
+ -> { where :placed_at.gte => Emarsys.config.export_interval.ago }
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module Workarea
2
+ decorate User, with: :emarsys do
3
+ decorated do
4
+ field :emarsys_exported_at, type: Time
5
+ field :emarsys_external_id, type: String
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,31 @@
1
+ module Workarea
2
+ module Emarsys
3
+ class Contact
4
+ class Order
5
+ attr_reader :order
6
+
7
+ def initialize(order)
8
+ @order = order
9
+ end
10
+
11
+ def email
12
+ order.email
13
+ end
14
+
15
+ def first_name
16
+ payment.address.first_name
17
+ end
18
+
19
+ def last_name
20
+ payment.address.last_name
21
+ end
22
+
23
+ private
24
+
25
+ def payment
26
+ Workarea::Payment.find(order.id)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ module Workarea
2
+ module Emarsys
3
+ class Contact
4
+ class User
5
+ attr_reader :user
6
+
7
+ def initialize(user)
8
+ @user = user
9
+ end
10
+
11
+ def email
12
+ user.email
13
+ end
14
+
15
+ def first_name
16
+ user.first_name
17
+ end
18
+
19
+ def last_name
20
+ user.last_name
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,55 @@
1
+ module Workarea
2
+ module Emarsys
3
+ class Contact
4
+ attr_reader :model, :options
5
+
6
+ def initialize(model, options = {})
7
+ @model = model
8
+ @options = options
9
+ end
10
+
11
+ # @return Hash
12
+ def to_h
13
+ user_data = {
14
+ "1" => contact_model.first_name,
15
+ "2" => contact_model.last_name,
16
+ "3" => contact_model.email
17
+ }
18
+
19
+ if address.present?
20
+ address_data = {
21
+ "10" => address.street,
22
+ "11" => address.city,
23
+ "12" => address.region,
24
+ "13" => address.postal_code,
25
+ "14" => ::Emarsys::Country.new.find_code(address.country.to_s),
26
+ "15" => address.phone_number
27
+ }
28
+
29
+ user_data.merge!(address_data)
30
+ end
31
+
32
+ user_data
33
+ end
34
+
35
+ private
36
+
37
+ def address
38
+ options[:address]
39
+ end
40
+
41
+ def contact_from
42
+ options[:contact_from]
43
+ end
44
+
45
+ def contact_model
46
+ if contact_from == "user"
47
+ Contact::User.new(model)
48
+ elsif contact_from == "order"
49
+ Contact::Order.new(model)
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ module Workarea
2
+ module Admin
3
+ class EmarsysConfigurationViewModel < ApplicationViewModel
4
+ def masked_api_key
5
+ return unless Workarea::Emarsys.secret_key.present?
6
+ key = Workarea::Emarsys.secret_key
7
+ last_digits = key.to_s.slice(-4..-1)
8
+ "XXXXXXXXXX#{last_digits}"
9
+ end
10
+
11
+ def masked_sales_api_key
12
+ return unless Workarea::Emarsys.api_token.present?
13
+ key = Workarea::Emarsys.api_token
14
+ last_digits = key.to_s.slice(-4..-1)
15
+ "XXXXXXXXXX#{last_digits}"
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,68 @@
1
+ - @page_title = t('workarea.admin.emarsys_configuration.edit.title')
2
+
3
+ .view
4
+ .view__header
5
+ .view__heading
6
+ = link_to "↑ #{t('workarea.admin.search_settings.show.dashboard_link')}", settings_dashboards_path
7
+ %h1= t('workarea.admin.emarsys_configuration.edit.title')
8
+
9
+ .view__container
10
+ = form_tag emarsys_configuration_path, method: :patch, data: { unsaved_changes: '' } do
11
+
12
+ .grid__cell.grid__cell--50-at-medium
13
+
14
+ .property
15
+ %span.property__name
16
+ = t('workarea.admin.emarsys_configuration.edit.api_key')
17
+ = link_to '#api-key', data: { tooltip: '' } do
18
+ = inline_svg('workarea/admin/icons/help.svg', class: 'svg-icon svg-icon--small svg-icon--blue', title: t('workarea.admin.emarsys_configuration.edit.api_key'))
19
+ #api-key.tooltip-content
20
+ %p= t('workarea.admin.emarsys_configuration.edit.help.api_key')
21
+
22
+ - if @configuration.masked_api_key.present?
23
+ %p= @configuration.masked_api_key
24
+ - else
25
+ %p= t('workarea.admin.emarsys_configuration.edit.no_key')
26
+
27
+ %span.property__name
28
+ = t('workarea.admin.emarsys_configuration.edit.sales_api_key')
29
+ = link_to '#sales-api-key', data: { tooltip: '' } do
30
+ = inline_svg('workarea/admin/icons/help.svg', class: 'svg-icon svg-icon--small svg-icon--blue', title: t('workarea.admin.emarsys_configuration.edit.sales_api_key'))
31
+ #sales-api-key.tooltip-content
32
+ %p= t('workarea.admin.emarsys_configuration.edit.help.sales_api_key')
33
+
34
+ - if @configuration.masked_sales_api_key.present?
35
+ %p= @configuration.masked_sales_api_key
36
+ - else
37
+ %p= t('workarea.admin.emarsys_configuration.edit.no_key')
38
+
39
+ %span.property__name
40
+ = t('workarea.admin.emarsys_configuration.edit.production')
41
+ = link_to '#enabled', data: { tooltip: '' } do
42
+ = inline_svg('workarea/admin/icons/help.svg', class: 'svg-icon svg-icon--small svg-icon--blue', title: t('workarea.admin.emarsys_configuration.edit.production'))
43
+ #enabled.tooltip-content
44
+ %p= t('workarea.admin.emarsys_configuration.edit.help.production')
45
+
46
+ = toggle_button_for 'production', @configuration.production?
47
+
48
+ %span.property__name
49
+ = t('workarea.admin.emarsys_configuration.edit.customer_id')
50
+ = link_to '#show-on-pdp', data: { tooltip: '' } do
51
+ = inline_svg('workarea/admin/icons/help.svg', class: 'svg-icon svg-icon--small svg-icon--blue', title: t('workarea.admin.emarsys_configuration.edit.customer_id'))
52
+ #show-on-pdp.tooltip-content
53
+ %p= t('workarea.admin.emarsys_configuration.edit.help.customer_id')
54
+
55
+ = text_field_tag 'customer_id', @configuration.customer_id, class: 'text-box', id: "customer_id"
56
+
57
+ %span.property__name
58
+ = t('workarea.admin.emarsys_configuration.edit.merchant_id')
59
+ = link_to '#show-on-cart', data: { tooltip: '' } do
60
+ = inline_svg('workarea/admin/icons/help.svg', class: 'svg-icon svg-icon--small svg-icon--blue', title: t('workarea.admin.emarsys_configuration.edit.merchant_id'))
61
+ #show-on-cart.tooltip-content
62
+ %p= t('workarea.admin.emarsys_configuration.edit.help.merchant_id')
63
+
64
+ = text_field_tag 'merchant_id', @configuration.merchant_id, class: 'text-box', id: "merchant_id"
65
+
66
+ .workflow-bar
67
+ .grid.grid--auto.grid--right.grid--middle
68
+ .grid__cell= button_tag t('workarea.admin.emarsys_configuration.edit.button'), value: 'save_settings', class: 'workflow-bar__button workflow-bar__button--update'
@@ -0,0 +1 @@
1
+ %li{ class: "primary-nav__item" }= link_to t('workarea.admin.shared.primary_nav.emarsys_configuration_title'), edit_emarsys_configuration_path, class: navigation_link_classes(edit_emarsys_configuration_path)
@@ -0,0 +1,11 @@
1
+ - if Workarea::Emarsys::Configuration.current.merchant_id.present?
2
+ :javascript
3
+ var ScarabQueue = ScarabQueue || [];
4
+ (function(id) {
5
+ if (document.getElementById(id)) return;
6
+ var js = document.createElement('script'); js.id = id;
7
+ js.src = '//cdn.scarabresearch.com/js/#{Workarea::Emarsys::Configuration.current.merchant_id}/scarab-v2.js';
8
+ var fs = document.getElementsByTagName('script')[0];
9
+ fs.parentNode.insertBefore(js, fs);
10
+ })('scarab-js-api');
11
+
@@ -0,0 +1,6 @@
1
+ json.email current_user&.email
2
+ json.emarsys_cart_items current_order.items do |item|
3
+ json.item item.product_id
4
+ json.quantity item.quantity
5
+ json.price item.total_price.amount.to_f
6
+ end