spree_delivery_distance 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: efc92011713d6c54242405539cd1eb64e621956d294f0b288422471cf76b6473
4
+ data.tar.gz: 65c9256f0b6eed2945a33ed9f2941a06c2fe2d349462be8bae5192d0d5ef84dd
5
+ SHA512:
6
+ metadata.gz: 908de7e44a975de5bdd3a4f22eadde409f491ff9d7a486fa86a2f56dba6ec9f31e9935eaaf6389dd5ec50eb5f7f0c00c692f33211f6de9e1e171f254e43b3ca2
7
+ data.tar.gz: ec5ac16ed99c74f2061ba4f57461978ece46f9e64a6b710d8769bc2f656f35c3eb1e09ae73cee3d3a610414cf3cc6d75d48acb11e57fbf813783005828dff0ef
@@ -0,0 +1,2 @@
1
+ spec/dummy/
2
+
@@ -0,0 +1 @@
1
+ 2.7.1
@@ -0,0 +1,20 @@
1
+ appraise 'spree-3-7' do
2
+ gem 'spree', '~> 3.7.0'
3
+ gem 'sass-rails'
4
+ gem 'rails-controller-testing'
5
+ end
6
+
7
+ appraise 'spree-4-0' do
8
+ gem 'spree', '~> 4.0.0'
9
+ gem 'rails-controller-testing'
10
+ end
11
+
12
+ appraise 'spree-4-1' do
13
+ gem 'spree', '~> 4.1.0'
14
+ gem 'rails-controller-testing'
15
+ end
16
+
17
+ appraise 'spree-master' do
18
+ gem 'spree', github: 'spree/spree', branch: 'master'
19
+ gem 'rails-controller-testing'
20
+ end
data/Gemfile ADDED
@@ -0,0 +1,28 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) do |repo_name|
4
+ repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
5
+ "https://github.com/#{repo_name}.git"
6
+ end
7
+
8
+ gem 'geocoder'
9
+
10
+ gem 'spree', github: 'spree/spree', branch: 'master'
11
+
12
+ group :test do
13
+ gem 'sqlite3'
14
+
15
+ gem 'rails-controller-testing'
16
+
17
+ gem 'database_cleaner'
18
+ gem 'factory_bot'
19
+
20
+ gem 'pry'
21
+ gem 'pry-byebug'
22
+ gem 'pry-stack_explorer', '~> 0.5.0'
23
+
24
+ gem 'rspec'
25
+ gem 'rspec-rails'
26
+ end
27
+
28
+ gemspec
@@ -0,0 +1,389 @@
1
+ GIT
2
+ remote: https://github.com/spree/spree.git
3
+ revision: 1612f29a77ec2996f5876eead9d388965f5f6c66
4
+ branch: master
5
+ specs:
6
+ spree (4.2.0.alpha)
7
+ spree_api (= 4.2.0.alpha)
8
+ spree_backend (= 4.2.0.alpha)
9
+ spree_cmd (= 4.2.0.alpha)
10
+ spree_core (= 4.2.0.alpha)
11
+ spree_frontend (= 4.2.0.alpha)
12
+ spree_sample (= 4.2.0.alpha)
13
+ spree_api (4.2.0.alpha)
14
+ doorkeeper (~> 5.2, >= 5.2.1)
15
+ fast_jsonapi (~> 1.5)
16
+ rabl (~> 0.14.2)
17
+ spree_core (= 4.2.0.alpha)
18
+ spree_backend (4.2.0.alpha)
19
+ bootstrap (>= 4.3.1, < 4.6.0)
20
+ flatpickr (~> 4.6.0)
21
+ glyphicons (~> 1.0.2)
22
+ inline_svg (~> 1.5)
23
+ jquery-rails (~> 4.3)
24
+ jquery-ui-rails (~> 6.0.1)
25
+ select2-rails (~> 3.5.0)
26
+ spree_api (= 4.2.0.alpha)
27
+ spree_core (= 4.2.0.alpha)
28
+ spree_cmd (4.2.0.alpha)
29
+ thor (~> 0.20.3)
30
+ spree_core (4.2.0.alpha)
31
+ activemerchant (~> 1.67)
32
+ acts_as_list (~> 0.8)
33
+ awesome_nested_set (>= 3.1.4, < 3.3.0)
34
+ cancancan (~> 3.0)
35
+ carmen (>= 1.0, < 1.2)
36
+ ffaker (~> 2.9)
37
+ friendly_id (>= 5.2.1, < 5.5.0)
38
+ highline (~> 2.0.0)
39
+ image_processing (~> 1.2)
40
+ kaminari (~> 1.2.1)
41
+ mini_magick (>= 4.9.4, < 4.11.0)
42
+ monetize (~> 1.9)
43
+ money (~> 6.13)
44
+ paranoia (~> 2.4.2)
45
+ premailer-rails
46
+ rails (~> 6.0.0)
47
+ ransack (~> 2.3.0)
48
+ responders
49
+ sprockets (~> 3.7)
50
+ sprockets-rails
51
+ state_machines-activemodel (~> 0.7)
52
+ state_machines-activerecord (~> 0.6)
53
+ stringex
54
+ twitter_cldr (>= 4.3, < 7.0)
55
+ spree_frontend (4.2.0.alpha)
56
+ bootstrap (>= 4.3.1, < 4.6.0)
57
+ canonical-rails (~> 0.2.5)
58
+ glyphicons (~> 1.0.2)
59
+ inline_svg (~> 1.5)
60
+ jquery-rails (~> 4.3)
61
+ spree_api (= 4.2.0.alpha)
62
+ spree_core (= 4.2.0.alpha)
63
+ turbolinks (~> 5.2.0)
64
+ spree_sample (4.2.0.alpha)
65
+ spree_core (= 4.2.0.alpha)
66
+
67
+ PATH
68
+ remote: .
69
+ specs:
70
+ spree_delivery_distance (0.0.1.alpha)
71
+ geocoder
72
+ spree_api (>= 3.2.0, < 5.0)
73
+ spree_backend (>= 3.2.0, < 5.0)
74
+ spree_core (>= 3.2.0, < 5.0)
75
+ spree_extension
76
+
77
+ GEM
78
+ remote: https://rubygems.org/
79
+ specs:
80
+ actioncable (6.0.3.2)
81
+ actionpack (= 6.0.3.2)
82
+ nio4r (~> 2.0)
83
+ websocket-driver (>= 0.6.1)
84
+ actionmailbox (6.0.3.2)
85
+ actionpack (= 6.0.3.2)
86
+ activejob (= 6.0.3.2)
87
+ activerecord (= 6.0.3.2)
88
+ activestorage (= 6.0.3.2)
89
+ activesupport (= 6.0.3.2)
90
+ mail (>= 2.7.1)
91
+ actionmailer (6.0.3.2)
92
+ actionpack (= 6.0.3.2)
93
+ actionview (= 6.0.3.2)
94
+ activejob (= 6.0.3.2)
95
+ mail (~> 2.5, >= 2.5.4)
96
+ rails-dom-testing (~> 2.0)
97
+ actionpack (6.0.3.2)
98
+ actionview (= 6.0.3.2)
99
+ activesupport (= 6.0.3.2)
100
+ rack (~> 2.0, >= 2.0.8)
101
+ rack-test (>= 0.6.3)
102
+ rails-dom-testing (~> 2.0)
103
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
104
+ actiontext (6.0.3.2)
105
+ actionpack (= 6.0.3.2)
106
+ activerecord (= 6.0.3.2)
107
+ activestorage (= 6.0.3.2)
108
+ activesupport (= 6.0.3.2)
109
+ nokogiri (>= 1.8.5)
110
+ actionview (6.0.3.2)
111
+ activesupport (= 6.0.3.2)
112
+ builder (~> 3.1)
113
+ erubi (~> 1.4)
114
+ rails-dom-testing (~> 2.0)
115
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
116
+ activejob (6.0.3.2)
117
+ activesupport (= 6.0.3.2)
118
+ globalid (>= 0.3.6)
119
+ activemerchant (1.112.0)
120
+ activesupport (>= 4.2)
121
+ builder (>= 2.1.2, < 4.0.0)
122
+ i18n (>= 0.6.9)
123
+ nokogiri (~> 1.4)
124
+ activemodel (6.0.3.2)
125
+ activesupport (= 6.0.3.2)
126
+ activerecord (6.0.3.2)
127
+ activemodel (= 6.0.3.2)
128
+ activesupport (= 6.0.3.2)
129
+ activestorage (6.0.3.2)
130
+ actionpack (= 6.0.3.2)
131
+ activejob (= 6.0.3.2)
132
+ activerecord (= 6.0.3.2)
133
+ marcel (~> 0.3.1)
134
+ activesupport (6.0.3.2)
135
+ concurrent-ruby (~> 1.0, >= 1.0.2)
136
+ i18n (>= 0.7, < 2)
137
+ minitest (~> 5.1)
138
+ tzinfo (~> 1.1)
139
+ zeitwerk (~> 2.2, >= 2.2.2)
140
+ acts_as_list (0.9.19)
141
+ activerecord (>= 3.0)
142
+ addressable (2.7.0)
143
+ public_suffix (>= 2.0.2, < 5.0)
144
+ autoprefixer-rails (9.8.6.3)
145
+ execjs
146
+ awesome_nested_set (3.2.1)
147
+ activerecord (>= 4.0.0, < 7.0)
148
+ binding_of_caller (0.8.0)
149
+ debug_inspector (>= 0.0.1)
150
+ bootstrap (4.5.2)
151
+ autoprefixer-rails (>= 9.1.0)
152
+ popper_js (>= 1.14.3, < 2)
153
+ sassc-rails (>= 2.0.0)
154
+ builder (3.2.4)
155
+ byebug (11.1.3)
156
+ camertron-eprun (1.1.1)
157
+ cancancan (3.1.0)
158
+ canonical-rails (0.2.9)
159
+ rails (>= 4.1, < 6.1)
160
+ carmen (1.1.3)
161
+ activesupport (>= 3.0.0)
162
+ cldr-plurals-runtime-rb (1.0.1)
163
+ coderay (1.1.3)
164
+ concurrent-ruby (1.1.7)
165
+ crass (1.0.6)
166
+ css_parser (1.7.1)
167
+ addressable
168
+ database_cleaner (1.8.5)
169
+ debug_inspector (0.0.3)
170
+ diff-lcs (1.4.4)
171
+ doorkeeper (5.4.0)
172
+ railties (>= 5)
173
+ erubi (1.9.0)
174
+ execjs (2.7.0)
175
+ factory_bot (4.11.1)
176
+ activesupport (>= 3.0.0)
177
+ fast_jsonapi (1.5)
178
+ activesupport (>= 4.2)
179
+ ffaker (2.17.0)
180
+ ffi (1.13.1)
181
+ flatpickr (4.6.3.1)
182
+ friendly_id (5.4.0)
183
+ activerecord (>= 4.0.0)
184
+ geocoder (1.6.3)
185
+ globalid (0.4.2)
186
+ activesupport (>= 4.2.0)
187
+ glyphicons (1.0.2)
188
+ highline (2.0.3)
189
+ htmlentities (4.3.4)
190
+ i18n (1.8.5)
191
+ concurrent-ruby (~> 1.0)
192
+ image_processing (1.11.0)
193
+ mini_magick (>= 4.9.5, < 5)
194
+ ruby-vips (>= 2.0.17, < 3)
195
+ inline_svg (1.7.1)
196
+ activesupport (>= 3.0)
197
+ nokogiri (>= 1.6)
198
+ jquery-rails (4.4.0)
199
+ rails-dom-testing (>= 1, < 3)
200
+ railties (>= 4.2.0)
201
+ thor (>= 0.14, < 2.0)
202
+ jquery-ui-rails (6.0.1)
203
+ railties (>= 3.2.16)
204
+ kaminari (1.2.1)
205
+ activesupport (>= 4.1.0)
206
+ kaminari-actionview (= 1.2.1)
207
+ kaminari-activerecord (= 1.2.1)
208
+ kaminari-core (= 1.2.1)
209
+ kaminari-actionview (1.2.1)
210
+ actionview
211
+ kaminari-core (= 1.2.1)
212
+ kaminari-activerecord (1.2.1)
213
+ activerecord
214
+ kaminari-core (= 1.2.1)
215
+ kaminari-core (1.2.1)
216
+ loofah (2.7.0)
217
+ crass (~> 1.0.2)
218
+ nokogiri (>= 1.5.9)
219
+ mail (2.7.1)
220
+ mini_mime (>= 0.1.1)
221
+ marcel (0.3.3)
222
+ mimemagic (~> 0.3.2)
223
+ method_source (1.0.0)
224
+ mimemagic (0.3.5)
225
+ mini_magick (4.10.1)
226
+ mini_mime (1.0.2)
227
+ mini_portile2 (2.4.0)
228
+ minitest (5.14.1)
229
+ monetize (1.9.4)
230
+ money (~> 6.12)
231
+ money (6.13.8)
232
+ i18n (>= 0.6.4, <= 2)
233
+ nio4r (2.5.2)
234
+ nokogiri (1.10.10)
235
+ mini_portile2 (~> 2.4.0)
236
+ paranoia (2.4.2)
237
+ activerecord (>= 4.0, < 6.1)
238
+ polyamorous (2.3.2)
239
+ activerecord (>= 5.2.1)
240
+ popper_js (1.16.0)
241
+ premailer (1.13.1)
242
+ addressable
243
+ css_parser (>= 1.6.0)
244
+ htmlentities (>= 4.0.0)
245
+ premailer-rails (1.11.1)
246
+ actionmailer (>= 3)
247
+ premailer (~> 1.7, >= 1.7.9)
248
+ pry (0.13.1)
249
+ coderay (~> 1.1)
250
+ method_source (~> 1.0)
251
+ pry-byebug (3.9.0)
252
+ byebug (~> 11.0)
253
+ pry (~> 0.13.0)
254
+ pry-stack_explorer (0.5.1)
255
+ binding_of_caller (~> 0.7)
256
+ pry (~> 0.13)
257
+ public_suffix (4.0.5)
258
+ rabl (0.14.3)
259
+ activesupport (>= 2.3.14)
260
+ rack (2.2.3)
261
+ rack-test (1.1.0)
262
+ rack (>= 1.0, < 3)
263
+ rails (6.0.3.2)
264
+ actioncable (= 6.0.3.2)
265
+ actionmailbox (= 6.0.3.2)
266
+ actionmailer (= 6.0.3.2)
267
+ actionpack (= 6.0.3.2)
268
+ actiontext (= 6.0.3.2)
269
+ actionview (= 6.0.3.2)
270
+ activejob (= 6.0.3.2)
271
+ activemodel (= 6.0.3.2)
272
+ activerecord (= 6.0.3.2)
273
+ activestorage (= 6.0.3.2)
274
+ activesupport (= 6.0.3.2)
275
+ bundler (>= 1.3.0)
276
+ railties (= 6.0.3.2)
277
+ sprockets-rails (>= 2.0.0)
278
+ rails-controller-testing (1.0.5)
279
+ actionpack (>= 5.0.1.rc1)
280
+ actionview (>= 5.0.1.rc1)
281
+ activesupport (>= 5.0.1.rc1)
282
+ rails-dom-testing (2.0.3)
283
+ activesupport (>= 4.2.0)
284
+ nokogiri (>= 1.6)
285
+ rails-html-sanitizer (1.3.0)
286
+ loofah (~> 2.3)
287
+ railties (6.0.3.2)
288
+ actionpack (= 6.0.3.2)
289
+ activesupport (= 6.0.3.2)
290
+ method_source
291
+ rake (>= 0.8.7)
292
+ thor (>= 0.20.3, < 2.0)
293
+ rake (13.0.1)
294
+ ransack (2.3.2)
295
+ activerecord (>= 5.2.1)
296
+ activesupport (>= 5.2.1)
297
+ i18n
298
+ polyamorous (= 2.3.2)
299
+ responders (3.0.1)
300
+ actionpack (>= 5.0)
301
+ railties (>= 5.0)
302
+ rspec (3.9.0)
303
+ rspec-core (~> 3.9.0)
304
+ rspec-expectations (~> 3.9.0)
305
+ rspec-mocks (~> 3.9.0)
306
+ rspec-core (3.9.2)
307
+ rspec-support (~> 3.9.3)
308
+ rspec-expectations (3.9.2)
309
+ diff-lcs (>= 1.2.0, < 2.0)
310
+ rspec-support (~> 3.9.0)
311
+ rspec-mocks (3.9.1)
312
+ diff-lcs (>= 1.2.0, < 2.0)
313
+ rspec-support (~> 3.9.0)
314
+ rspec-rails (4.0.1)
315
+ actionpack (>= 4.2)
316
+ activesupport (>= 4.2)
317
+ railties (>= 4.2)
318
+ rspec-core (~> 3.9)
319
+ rspec-expectations (~> 3.9)
320
+ rspec-mocks (~> 3.9)
321
+ rspec-support (~> 3.9)
322
+ rspec-support (3.9.3)
323
+ ruby-vips (2.0.17)
324
+ ffi (~> 1.9)
325
+ sassc (2.4.0)
326
+ ffi (~> 1.9)
327
+ sassc-rails (2.1.2)
328
+ railties (>= 4.0.0)
329
+ sassc (>= 2.0)
330
+ sprockets (> 3.0)
331
+ sprockets-rails
332
+ tilt
333
+ select2-rails (3.5.10)
334
+ thor (~> 0.14)
335
+ spree_extension (0.0.9)
336
+ activerecord (>= 4.2)
337
+ spree_core
338
+ sprockets (3.7.2)
339
+ concurrent-ruby (~> 1.0)
340
+ rack (> 1, < 3)
341
+ sprockets-rails (3.2.1)
342
+ actionpack (>= 4.0)
343
+ activesupport (>= 4.0)
344
+ sprockets (>= 3.0.0)
345
+ sqlite3 (1.4.2)
346
+ state_machines (0.5.0)
347
+ state_machines-activemodel (0.7.1)
348
+ activemodel (>= 4.1)
349
+ state_machines (>= 0.5.0)
350
+ state_machines-activerecord (0.6.0)
351
+ activerecord (>= 4.1)
352
+ state_machines-activemodel (>= 0.5.0)
353
+ stringex (2.8.5)
354
+ thor (0.20.3)
355
+ thread_safe (0.3.6)
356
+ tilt (2.0.10)
357
+ turbolinks (5.2.1)
358
+ turbolinks-source (~> 5.2)
359
+ turbolinks-source (5.2.0)
360
+ twitter_cldr (6.1.0)
361
+ camertron-eprun
362
+ cldr-plurals-runtime-rb (~> 1.0)
363
+ tzinfo
364
+ tzinfo (1.2.7)
365
+ thread_safe (~> 0.1)
366
+ websocket-driver (0.7.3)
367
+ websocket-extensions (>= 0.1.0)
368
+ websocket-extensions (0.1.5)
369
+ zeitwerk (2.4.0)
370
+
371
+ PLATFORMS
372
+ ruby
373
+
374
+ DEPENDENCIES
375
+ database_cleaner
376
+ factory_bot
377
+ geocoder
378
+ pry
379
+ pry-byebug
380
+ pry-stack_explorer (~> 0.5.0)
381
+ rails-controller-testing
382
+ rspec
383
+ rspec-rails
384
+ spree!
385
+ spree_delivery_distance!
386
+ sqlite3
387
+
388
+ BUNDLED WITH
389
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2020 [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.
@@ -0,0 +1,52 @@
1
+ # SpreeDeliveryDistance
2
+
3
+ - calculate distance between delivery address and theprimary shop or city center to approximate distance on delivery the package.
4
+
5
+
6
+ ## Installation
7
+
8
+ 1. Add this extension to your Gemfile with this line:
9
+
10
+ ```ruby
11
+ gem 'spree_delivery_distance', github: '[your-github-handle]/spree_delivery_distance'
12
+ ```
13
+
14
+ 2. Install the gem using Bundler
15
+
16
+ ```ruby
17
+ bundle install
18
+ ```
19
+
20
+ 3. Copy & run migrations
21
+
22
+ ```ruby
23
+ bundle exec rails g spree_delivery_distance:install
24
+ ```
25
+
26
+ 4. Restart your server
27
+
28
+ If your server was running, restart it so that it can find the assets properly.
29
+
30
+ ## Testing
31
+
32
+ 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`.
33
+
34
+ ```shell
35
+ bundle
36
+ bundle exec rake
37
+ ```
38
+
39
+ When testing your applications integration with this extension you may use it's factories.
40
+ Simply add this require statement to your spec_helper:
41
+
42
+ ```ruby
43
+ require 'spree_delivery_distance/factories'
44
+ ```
45
+
46
+ ## Contributing
47
+
48
+ If you'd like to contribute, please take a look at the
49
+ [instructions](CONTRIBUTING.md) for installing dependencies and crafting a good
50
+ pull request.
51
+
52
+ Copyright (c) 2020 [name of extension creator], released under the New BSD License
@@ -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_delivery_distance'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
@@ -0,0 +1,36 @@
1
+ module SpreeDeliveryDistance
2
+ module Spree
3
+ module AddressDecorator
4
+ def self.prepended(base)
5
+ base.geocoded_by :full_address do |obj, results|
6
+ geo = results.first
7
+
8
+ if geo
9
+ obj.latitude = geo.latitude
10
+ obj.longitude = geo.longitude
11
+ else
12
+ obj.errors.add :base, :cant_geocode
13
+ end
14
+ end
15
+
16
+ base.after_validation :geocode, on: [:create, :update]
17
+ end
18
+
19
+ ##
20
+ # The full address.
21
+ #
22
+ # @example Get the full address.
23
+ # address.full_address # "street, city, state, country"
24
+ #
25
+ # @return [String] The full street address wit city, state and country.
26
+ #
27
+ def full_address
28
+ [address1, address2.presence, city, state_text, country.try(:iso)].compact.join(', ')
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ if ::Spree::Address.included_modules.exclude?(SpreeDeliveryDistance::Spree::AddressDecorator)
35
+ ::Spree::Address.prepend SpreeDeliveryDistance::Spree::AddressDecorator
36
+ end
@@ -0,0 +1,43 @@
1
+ require 'geocoder'
2
+
3
+ module SpreeDeliveryDistance
4
+ module Spree
5
+
6
+ class DeliveryDistanceConfiguration < ::Spree::Preferences::Configuration
7
+ preference :distance_delivery_center_enabled, :boolean, default: true
8
+ preference :distance_delivery_center_lng, :float, default: nil
9
+ preference :distance_delivery_center_ltd, :float, default: nil
10
+ preference :distance_delivery_center_max_distance, :float, default: 60.0
11
+ preference :distance_delivery_center_address, :string, default: nil
12
+
13
+ def distance_delivery_center
14
+ return unless distance_delivery_center_enabled
15
+
16
+ if distance_delivery_center_ltd.nil? || distance_delivery_center_lng.nil?
17
+ if distance_delivery_center_address.blank?
18
+ raise 'missing distance_delivery_center_address'
19
+ end
20
+
21
+ results = Geocoder.search(distance_delivery_center_address)
22
+ if results.blank?
23
+ raise 'configure properly distance_delivery_center_address'
24
+ end
25
+ location = results.first
26
+ distance_delivery_center_ltd, distance_delivery_center_lng =
27
+ location.latitude, location.longitude
28
+ else
29
+ [
30
+ distance_delivery_center_ltd,
31
+ distance_delivery_center_lng
32
+ ]
33
+ end
34
+ end
35
+ end
36
+
37
+ #
38
+ # Example:
39
+ #
40
+ # DD_CONFIG = SpreeDeliveryDistance::Spree::DeliveryDistanceConfiguration.new
41
+ #
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ module SpreeDeliveryDistance
2
+ module Spree
3
+ module OrderDecorator
4
+ def self.prepended(base)
5
+ base.after_validation :distance_delivery_ship_address, on: [:create, :update]
6
+ end
7
+
8
+ def distance_delivery_ship_address
9
+ return if ship_address.nil?
10
+
11
+ if ship_address.latitude.blank? || ship_address.longitude.blank?
12
+ ship_address.geocode
13
+ ship_address.save
14
+ end
15
+
16
+ distance = ship_address.distance_to(DELIVERY_DISTANCE_CONFIG.distance_delivery_center).to_f
17
+ max_distance = DELIVERY_DISTANCE_CONFIG.distance_delivery_center_max_distance.to_f
18
+ return unless distance > max_distance
19
+
20
+ errors.add :ship_address, :address_is_too_far
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ if ::Spree::Order.included_modules.exclude?(SpreeDeliveryDistance::Spree::OrderDecorator)
27
+ ::Spree::Order.prepend SpreeDeliveryDistance::Spree::OrderDecorator
28
+ end
@@ -0,0 +1,22 @@
1
+ Geocoder.configure(
2
+ # Geocoding options
3
+ timeout: 10, # geocoding service timeout (secs)
4
+ # lookup: :nominatim, # name of geocoding service (symbol)
5
+ # ip_lookup: :ipinfo_io, # name of IP address geocoding service (symbol)
6
+ # language: :en, # ISO-639 language code
7
+ # use_https: false, # use HTTPS for lookup requests? (if supported)
8
+ # http_proxy: nil, # HTTP proxy server (user:pass@host:port)
9
+ # https_proxy: nil, # HTTPS proxy server (user:pass@host:port)
10
+ # api_key: nil, # API key for geocoding service
11
+ # cache: nil, # cache object (must respond to #[], #[]=, and #del)
12
+ # cache_prefix: 'geocoder:', # prefix (string) to use for all cache keys
13
+
14
+ # Exceptions that should not be rescued by default
15
+ # (if you want to implement custom error handling);
16
+ # supports SocketError and Timeout::Error
17
+ # always_raise: [],
18
+
19
+ # Calculation options
20
+ units: :km, # :km for kilometers or :mi for miles
21
+ # distances: :linear # :spherical or :linear
22
+ )
@@ -0,0 +1 @@
1
+ DELIVERY_DISTANCE_CONFIG = SpreeDeliveryDistance::Spree::DeliveryDistanceConfiguration.new
@@ -0,0 +1,12 @@
1
+ en:
2
+ activerecord:
3
+ errors:
4
+ models:
5
+ spree/address:
6
+ attributes:
7
+ base:
8
+ cant_geocode: "Can't find earth coordinates by using full address"
9
+ spree/order:
10
+ attributes:
11
+ ship_address:
12
+ address_is_too_far: "Your house is not in delivery area"
@@ -0,0 +1,6 @@
1
+ class AddLatitudeLongitudeToSpreeAddresses < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :spree_addresses, :latitude, :float
4
+ add_column :spree_addresses, :longitude, :float
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ module Spree
2
+ module DeliveryDistance
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+ class_option :migrate, type: :boolean, default: true, banner: 'Migrate the database'
6
+
7
+ def self.source_paths
8
+ paths = superclass.source_paths
9
+ paths << File.expand_path('../templates', __FILE__)
10
+ paths.flatten
11
+ end
12
+
13
+ def add_migrations
14
+ run 'bundle exec rake railties:install:migrations FROM=spree_delivery_distance'
15
+ end
16
+
17
+ def run_migrations
18
+ if options[:migrate]
19
+ run 'bundle exec rake db:migrate VERBOSE=false'
20
+ else
21
+ puts "Skiping rake db:migrate, don't forget to run it!"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ # Example
2
+ # DELIVERY_DISTANCE_CONFIG[:distance_delivery_center_enabled] = true
3
+ # DELIVERY_DISTANCE_CONFIG[:distance_delivery_center_address] = 'Barcelona, Spain'
4
+ # DELIVERY_DISTANCE_CONFIG[:distance_delivery_center_max_distance] = 50
@@ -0,0 +1,4 @@
1
+ require 'spree_core'
2
+ require 'spree_extension'
3
+ require 'spree_delivery_distance/engine'
4
+ require 'spree_delivery_distance/version'
@@ -0,0 +1,20 @@
1
+ module SpreeDeliveryDistance
2
+ class Engine < Rails::Engine
3
+ require 'spree/core'
4
+ isolate_namespace Spree
5
+ engine_name 'spree_delivery_distance'
6
+
7
+ # use rspec for tests
8
+ config.generators do |g|
9
+ g.test_framework :rspec
10
+ end
11
+
12
+ def self.activate
13
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
14
+ Rails.configuration.cache_classes ? require(c) : load(c)
15
+ end
16
+ end
17
+
18
+ config.to_prepare(&method(:activate).to_proc)
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ FactoryBot.define do
2
+ # Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
3
+ #
4
+ # Example adding this to your spec_helper will load these Factories for use:
5
+ # require 'spree_refer_by_qrcode/factories'
6
+ end
@@ -0,0 +1,18 @@
1
+ module SpreeDeliveryDistance
2
+ module_function
3
+
4
+ # Returns the version of the currently loaded SpreeDeliveryDistance as a
5
+ # <tt>Gem::Version</tt>.
6
+ def version
7
+ Gem::Version.new VERSION::STRING
8
+ end
9
+
10
+ module VERSION
11
+ MAJOR = 0
12
+ MINOR = 0
13
+ TINY = 1
14
+ PRE = 'alpha'.freeze
15
+
16
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: UTF-8
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'spree_delivery_distance/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.platform = Gem::Platform::RUBY
9
+ s.name = 'spree_delivery_distance'
10
+ s.version = SpreeDeliveryDistance.version
11
+ s.summary = 'Add extension summary here'
12
+ s.description = 'Add (optional) extension description here'
13
+ s.required_ruby_version = '>= 2.2.7'
14
+
15
+ s.author = 'Team'
16
+ s.email = 'team@bitscorp.com'
17
+ s.homepage = 'https://github.com/your-github-handle/spree_refer_by_qrcode'
18
+ s.license = 'BSD-3-Clause'
19
+
20
+ s.files = `git ls-files`.split("\n").reject { |f| f.match(/^spec/) && !f.match(/^spec\/fixtures/) }
21
+ s.require_path = 'lib'
22
+ s.requirements << 'none'
23
+
24
+ spree_version = '>= 3.2.0', '< 5.0'
25
+ s.add_dependency 'spree_core', spree_version
26
+ s.add_dependency 'spree_api', spree_version
27
+ s.add_dependency 'spree_backend', spree_version
28
+ s.add_dependency 'spree_extension'
29
+ s.add_dependency 'geocoder'
30
+
31
+ # s.add_development_dependency 'spree_dev_tools'
32
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_delivery_distance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spree_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: spree_api
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.2.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.2.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: spree_backend
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 3.2.0
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '5.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 3.2.0
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '5.0'
73
+ - !ruby/object:Gem::Dependency
74
+ name: spree_extension
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ - !ruby/object:Gem::Dependency
88
+ name: geocoder
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ type: :runtime
95
+ prerelease: false
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ description: Add (optional) extension description here
102
+ email: team@bitscorp.com
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - ".ruby-version"
109
+ - Appraisals
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE
113
+ - README.md
114
+ - Rakefile
115
+ - app/models/spree_delivery_distance/spree/address_decorator.rb
116
+ - app/models/spree_delivery_distance/spree/delivery_distance_configuration.rb
117
+ - app/models/spree_delivery_distance/spree/order_decorator.rb
118
+ - config/initializers/geocoder.rb
119
+ - config/initializers/spree_delivery_distance.rb
120
+ - config/locales/en.yml
121
+ - db/migrate/20200827145937_add_latitude_longitude_to_spree_addresses.rb
122
+ - lib/generators/spree/delivery_distance/install/install_generator.rb
123
+ - lib/generators/spree/delivery_distance/templates/config/initializers/spree_delivery_distance.rb
124
+ - lib/spree_delivery_distance.rb
125
+ - lib/spree_delivery_distance/engine.rb
126
+ - lib/spree_delivery_distance/factories.rb
127
+ - lib/spree_delivery_distance/version.rb
128
+ - spree_delivery_distance.gemspec
129
+ homepage: https://github.com/your-github-handle/spree_refer_by_qrcode
130
+ licenses:
131
+ - BSD-3-Clause
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: 2.2.7
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">"
145
+ - !ruby/object:Gem::Version
146
+ version: 1.3.1
147
+ requirements:
148
+ - none
149
+ rubygems_version: 3.1.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Add extension summary here
153
+ test_files: []