geo_settings 0.30.0.beta
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.
- data/LICENSE +23 -0
- data/README.md +18 -0
- data/app/controllers/admin/geo_settings_controller.rb +24 -0
- data/app/controllers/checkout_controller_decorator.rb +30 -0
- data/app/controllers/geo_settings_controller.rb +23 -0
- data/app/views/admin/geo_settings/edit.html.slim +24 -0
- data/app/views/admin/geo_settings/show.html.slim +44 -0
- data/lib/geo_settings.rb +31 -0
- data/lib/geo_settings_hooks.rb +13 -0
- data/lib/google_maps.rb +8 -0
- data/lib/google_maps/directions.rb +28 -0
- data/lib/tasks/geo_settings.rake +1 -0
- data/lib/tasks/install.rake +26 -0
- metadata +164 -0
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Redistribution and use in source and binary forms, with or without modification,
|
2
|
+
are permitted provided that the following conditions are met:
|
3
|
+
|
4
|
+
* Redistributions of source code must retain the above copyright notice,
|
5
|
+
this list of conditions and the following disclaimer.
|
6
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
7
|
+
this list of conditions and the following disclaimer in the documentation
|
8
|
+
and/or other materials provided with the distribution.
|
9
|
+
* Neither the name of the Rails Dog LLC nor the names of its
|
10
|
+
contributors may be used to endorse or promote products derived from this
|
11
|
+
software without specific prior written permission.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
14
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
15
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
16
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
17
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
18
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
19
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
20
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
21
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
22
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
23
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
GeoSettings
|
2
|
+
===========
|
3
|
+
|
4
|
+
Extension for calculating distance for delivery. Based on entered delivery distance, extension calculate if shipping address is in that distance. If it is not order can not be proceeded. Distance is calculated based on driving direction.
|
5
|
+
|
6
|
+
You could managed following preferences:
|
7
|
+
|
8
|
+
* address - address of your store
|
9
|
+
* time_to_delivery - approximate time to deliver order
|
10
|
+
* minimum_order - minimum value of order
|
11
|
+
* delivery_distance - distance in within you deliver orders
|
12
|
+
|
13
|
+
Installation
|
14
|
+
============
|
15
|
+
|
16
|
+
1. Add `gem "geo_settings"` to your Gemfile
|
17
|
+
1. Run `bundle install`
|
18
|
+
1. Run `rails g geo_settings:install`
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Admin::GeoSettingsController < Admin::BaseController
|
2
|
+
before_filter :set_geolocation, :only => [:show]
|
3
|
+
|
4
|
+
def update
|
5
|
+
Spree::Config.set(params[:preferences])
|
6
|
+
|
7
|
+
respond_to do |f|
|
8
|
+
f.html {
|
9
|
+
redirect_to admin_geo_settings_path
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def set_geolocation
|
16
|
+
if Spree::Config[:address].present?
|
17
|
+
@lat = Geokit::Geocoders::YahooGeocoder.geocode(Spree::Config[:address]).lat
|
18
|
+
@lng = Geokit::Geocoders::YahooGeocoder.geocode(Spree::Config[:address]).lng
|
19
|
+
else
|
20
|
+
@lat, @lng = nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
CheckoutController.class_eval do
|
2
|
+
include GoogleMaps
|
3
|
+
|
4
|
+
before_filter :check_delivery_distance
|
5
|
+
|
6
|
+
private
|
7
|
+
def check_delivery_distance
|
8
|
+
if params[:state] == "address" && params[:order]
|
9
|
+
get_distance
|
10
|
+
|
11
|
+
if @distance.kind_of?(Float) && @distance > Spree::Config[:delivery_distance].to_f
|
12
|
+
flash[:error] = t('out_of_range', :distance => Spree::Config[:delivery_distance])
|
13
|
+
redirect_to checkout_state_path(@order.state)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_distance
|
19
|
+
@distance = GoogleMaps::Directions.get_distance( Spree::Config[:address], get_address(params))
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_address(opts={})
|
23
|
+
if opts[:order][:ship_address_attributes].has_key?(:address1)
|
24
|
+
"#{opts[:order][:ship_address_attributes][:address1]}, #{opts[:order][:ship_address_attributes][:city]}"
|
25
|
+
else
|
26
|
+
"#{opts[:order][:bill_address_attributes][:address1]}, #{opts[:order][:bill_address_attributes][:city]}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class GeoSettingsController < ApplicationController
|
2
|
+
|
3
|
+
def check_address
|
4
|
+
unless params[:address].blank?
|
5
|
+
@address, session[:address] = params[:address], params[:address]
|
6
|
+
|
7
|
+
@distance = GoogleMaps::Directions.get_distance( Spree::Config[:address], params[:address])
|
8
|
+
|
9
|
+
if @distance.kind_of?(Float) && @distance > Spree::Config[:delivery_distance].to_f
|
10
|
+
@respond = false
|
11
|
+
else
|
12
|
+
@respond = true
|
13
|
+
end
|
14
|
+
else
|
15
|
+
@respond = false
|
16
|
+
end
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.js { render :json => { :response => @respond }.to_json }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
= render :partial => 'admin/shared/configuration_menu'
|
2
|
+
|
3
|
+
h1 = t('geo_settings')
|
4
|
+
|
5
|
+
- form_tag(admin_geo_settings_path, :method => :put) do
|
6
|
+
p
|
7
|
+
= label_tag t('address')
|
8
|
+
= text_field_tag 'preferences[address]', Spree::Config[:address]
|
9
|
+
p
|
10
|
+
= label_tag t('delivery_distance')
|
11
|
+
= text_field_tag 'preferences[delivery_distance]', Spree::Config[:delivery_distance]
|
12
|
+
span.label= Spree::Config[:default_units]
|
13
|
+
p
|
14
|
+
= label_tag t('time_to_deliver')
|
15
|
+
= text_field_tag 'preferences[time_to_deliver]', Spree::Config[:time_to_deliver]
|
16
|
+
span.label min
|
17
|
+
p
|
18
|
+
= label_tag t('minimum_order')
|
19
|
+
= text_field_tag 'preferences[minimum_order]', Spree::Config[:minimum_order]
|
20
|
+
span.label €
|
21
|
+
p.form-buttons
|
22
|
+
= button t('update')
|
23
|
+
= t("or")
|
24
|
+
= link_to t("cancel"), admin_geo_settings_url
|
@@ -0,0 +1,44 @@
|
|
1
|
+
- content_for :head do
|
2
|
+
= javascript_include_tag 'http://maps.google.com/maps/api/js?sensor=false'
|
3
|
+
= javascript_include_tag 'admin/geo.js'
|
4
|
+
= stylesheet_link_tag 'admin/geo.css'
|
5
|
+
|
6
|
+
= render :partial => 'admin/shared/configuration_menu'
|
7
|
+
|
8
|
+
div#geo-wrapper
|
9
|
+
div#geo-settings
|
10
|
+
h1= t("geo_settings")
|
11
|
+
|
12
|
+
div
|
13
|
+
h2= t('address')
|
14
|
+
- if Spree::Config[:address]
|
15
|
+
p
|
16
|
+
= "#{Spree::Config[:address]}, (#{@lat}, #{@lng})"
|
17
|
+
h2= t('delivery_distance')
|
18
|
+
- if Spree::Config[:delivery_distance]
|
19
|
+
p
|
20
|
+
= "#{Spree::Config[:delivery_distance]}"
|
21
|
+
span.label= Geokit::default_units
|
22
|
+
h2= t('time_to_deliver')
|
23
|
+
- if Spree::Config[:time_to_deliver]
|
24
|
+
p
|
25
|
+
= "#{Spree::Config[:time_to_deliver]}"
|
26
|
+
span.label min
|
27
|
+
div
|
28
|
+
h2= t('minimum_order')
|
29
|
+
- if Spree::Config[:minimum_order]
|
30
|
+
p
|
31
|
+
= "#{Spree::Config[:minimum_order]}"
|
32
|
+
span.label €
|
33
|
+
p
|
34
|
+
= link_to_with_icon 'edit', t("edit"), edit_admin_geo_settings_path
|
35
|
+
|
36
|
+
div#geo-map
|
37
|
+
- if @lat && @lng
|
38
|
+
div#map-canvas
|
39
|
+
|
40
|
+
javascript:
|
41
|
+
var address = "#{Spree::Config[:address]}";
|
42
|
+
var distance = "#{Spree::Config[:delivery_distance]}";
|
43
|
+
var lat = "#{@lat}";
|
44
|
+
var lng = "#{@lng}";
|
data/lib/geo_settings.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spree_core'
|
2
|
+
require 'geo_settings_hooks'
|
3
|
+
|
4
|
+
module GeoSettings
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
def self.activate
|
10
|
+
require 'geokit'
|
11
|
+
require 'slim/rails'
|
12
|
+
|
13
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
|
14
|
+
Rails.env.production? ? require(c) : load(c)
|
15
|
+
end
|
16
|
+
|
17
|
+
Geokit::default_units = :kms
|
18
|
+
|
19
|
+
AppConfiguration.class_eval do
|
20
|
+
preference :address, :string
|
21
|
+
preference :time_to_delivery, :integer
|
22
|
+
preference :minimum_order, :float
|
23
|
+
preference :default_units, :string, :default => Geokit::default_units
|
24
|
+
preference :delivery_distance, :float, :default => 2
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
config.to_prepare &method(:activate).to_proc
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class GeoSettingsHooks < Spree::ThemeSupport::HookListener
|
2
|
+
insert_after(:admin_configurations_menu) do
|
3
|
+
%(<tr>
|
4
|
+
<td><%= link_to t(:geo_settings), admin_geo_settings_url %></td>
|
5
|
+
<td><%= t(:geo_settings_description) %></td>
|
6
|
+
</tr>)
|
7
|
+
end
|
8
|
+
|
9
|
+
insert_after :admin_configurations_sidebar_menu do
|
10
|
+
%(<li<%= raw(' class="active"') if controller.controller_name == 'geo_settings' %>>
|
11
|
+
<%= link_to t(:geo_settings), admin_geo_settings_path %></li>)
|
12
|
+
end
|
13
|
+
end
|
data/lib/google_maps.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'yajl'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module GoogleMaps
|
6
|
+
String.class_eval do
|
7
|
+
def uri_escape
|
8
|
+
URI.escape(self, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Directions
|
13
|
+
def self.get_distance(from, to)
|
14
|
+
api_url = "http://maps.google.com/maps/api/directions/json"
|
15
|
+
|
16
|
+
url = api_url + "?origin=#{from.uri_escape}&destination=#{to.uri_escape}&sensor=false"
|
17
|
+
|
18
|
+
result = Yajl::Parser.parse(HTTParty.get(url).body)
|
19
|
+
|
20
|
+
if result["status"] == "OK"
|
21
|
+
result["routes"].first["legs"].first["distance"]["value"] / Float(1000)
|
22
|
+
else
|
23
|
+
result["status"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# add custom rake tasks here
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :geo_settings do
|
2
|
+
desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
|
3
|
+
task :install do
|
4
|
+
Rake::Task['geo_settings:install:migrations'].invoke
|
5
|
+
Rake::Task['geo_settings:install:assets'].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :install do
|
9
|
+
desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
|
10
|
+
task :migrations do
|
11
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'db')
|
12
|
+
destination = File.join(Rails.root, 'db')
|
13
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
14
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
|
18
|
+
task :assets do
|
19
|
+
source = File.join(File.dirname(__FILE__), '..', '..', 'public')
|
20
|
+
destination = File.join(Rails.root, 'public')
|
21
|
+
puts "INFO: Mirroring assets from #{source} to #{destination}"
|
22
|
+
Spree::FileUtilz.mirror_files(source, destination)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geo_settings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31098289
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 30
|
9
|
+
- 0
|
10
|
+
- beta
|
11
|
+
version: 0.30.0.beta
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Peter Zlatnar
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-11-05 00:00:00 +01:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
name: spree_core
|
26
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 299253690
|
32
|
+
segments:
|
33
|
+
- 0
|
34
|
+
- 30
|
35
|
+
- 0
|
36
|
+
- beta2
|
37
|
+
version: 0.30.0.beta2
|
38
|
+
requirement: *id001
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
name: geokit
|
43
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 3
|
49
|
+
segments:
|
50
|
+
- 1
|
51
|
+
- 5
|
52
|
+
- 0
|
53
|
+
version: 1.5.0
|
54
|
+
requirement: *id002
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
name: slim
|
59
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ~>
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
- 7
|
68
|
+
- 0
|
69
|
+
version: 0.7.0
|
70
|
+
requirement: *id003
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
type: :runtime
|
73
|
+
prerelease: false
|
74
|
+
name: yajl-ruby
|
75
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ~>
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 19
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
- 7
|
84
|
+
- 8
|
85
|
+
version: 0.7.8
|
86
|
+
requirement: *id004
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
name: httparty
|
91
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 5
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
- 6
|
100
|
+
- 1
|
101
|
+
version: 0.6.1
|
102
|
+
requirement: *id005
|
103
|
+
description: Restrict orders to local area for spree.
|
104
|
+
email: peter.zlatnar@gmail.com
|
105
|
+
executables: []
|
106
|
+
|
107
|
+
extensions: []
|
108
|
+
|
109
|
+
extra_rdoc_files: []
|
110
|
+
|
111
|
+
files:
|
112
|
+
- README.md
|
113
|
+
- LICENSE
|
114
|
+
- lib/geo_settings.rb
|
115
|
+
- lib/geo_settings_hooks.rb
|
116
|
+
- lib/google_maps/directions.rb
|
117
|
+
- lib/google_maps.rb
|
118
|
+
- lib/tasks/geo_settings.rake
|
119
|
+
- lib/tasks/install.rake
|
120
|
+
- app/controllers/admin/geo_settings_controller.rb
|
121
|
+
- app/controllers/checkout_controller_decorator.rb
|
122
|
+
- app/controllers/geo_settings_controller.rb
|
123
|
+
- app/views/admin/geo_settings/edit.html.slim
|
124
|
+
- app/views/admin/geo_settings/show.html.slim
|
125
|
+
has_rdoc: true
|
126
|
+
homepage: http://github.com/peterz/spree-geo-settings
|
127
|
+
licenses: []
|
128
|
+
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 57
|
140
|
+
segments:
|
141
|
+
- 1
|
142
|
+
- 8
|
143
|
+
- 7
|
144
|
+
version: 1.8.7
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
hash: 25
|
151
|
+
segments:
|
152
|
+
- 1
|
153
|
+
- 3
|
154
|
+
- 1
|
155
|
+
version: 1.3.1
|
156
|
+
requirements:
|
157
|
+
- none
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 1.3.7
|
160
|
+
signing_key:
|
161
|
+
specification_version: 3
|
162
|
+
summary: Restrict orders to local area for spree.
|
163
|
+
test_files: []
|
164
|
+
|