spree_delivery_options 2.1.4 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/app/assets/javascripts/store/delivery_time_options.js +44 -0
- data/app/assets/javascripts/store/spree_delivery_options.js +2 -0
- data/app/assets/stylesheets/store/delivery_checkout.scss +4 -0
- data/app/models/spree/order_decorator.rb +20 -2
- data/app/views/spree/checkout/_delivery_date.haml +5 -2
- data/lib/generators/spree_delivery_options/install/install_generator.rb +2 -1
- data/lib/spree_delivery_options/configuration.rb +1 -1
- data/spec/models/order_spec.rb +77 -38
- data/spree_delivery_options.gemspec +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2687fc3ca83448a1dbbe09f2d3f1b699c0ccf466
|
4
|
+
data.tar.gz: 4da57adfa9deadb80c321ada0d0c4369c0bef9a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3800bdad3b2642aa0136e29a7c90b1bb1687d2b46c3ba0440803b922d29d7093a84be3ba1f7204683c8cc34025f8f50401e255bb7ce5a7baba80a44ac27a5b76
|
7
|
+
data.tar.gz: 0d82f9a28fef33050f4ae2227da85d646fd26d7b630e922aa0416748a7a5666644946642b917e516aaae836c1d6758915b91db1776e6b208f22484f9c9d64615
|
data/README.md
CHANGED
@@ -43,11 +43,11 @@ Configuration
|
|
43
43
|
Both the delivery cut off hour and the delivery time options can be configured in your application.rb file
|
44
44
|
|
45
45
|
config.after_initialize do
|
46
|
-
delivery_time_options = {
|
47
|
-
|
48
|
-
|
46
|
+
delivery_time_options = {
|
47
|
+
monday: ["Before 6am", "9-12 am"],
|
48
|
+
tuesday: ["Before 6am", "9-12 am"]
|
49
49
|
}.to_json
|
50
50
|
SpreeDeliveryOptions::Config.delivery_time_options = delivery_time_options
|
51
51
|
SpreeDeliveryOptions::Config.delivery_cut_off_hour = 12
|
52
|
-
end
|
52
|
+
end
|
53
53
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
function SpreeDeliveryOptions() {
|
2
|
+
|
3
|
+
var that = this;
|
4
|
+
|
5
|
+
this.initializeDeliveryTimeSelect = function() {
|
6
|
+
this.update_delivery_time_options();
|
7
|
+
|
8
|
+
$('#order_delivery_date').change(function(event){
|
9
|
+
that.update_delivery_time_options();
|
10
|
+
});
|
11
|
+
};
|
12
|
+
|
13
|
+
this.update_delivery_time_options = function() {
|
14
|
+
delivery_time_options = $.parseJSON($('.delivery-time-options').attr("data"));
|
15
|
+
|
16
|
+
if (delivery_time_options){
|
17
|
+
weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
|
18
|
+
day_index = new Date($('#order_delivery_date').val()).getDay();
|
19
|
+
weekday = weekdays[day_index];
|
20
|
+
|
21
|
+
day_options = delivery_time_options[weekday];
|
22
|
+
this.populate_delivery_time(day_options);
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
this.populate_delivery_time = function(options) {
|
27
|
+
if (options) {
|
28
|
+
var arLen = options.length;
|
29
|
+
var newList = "";
|
30
|
+
for ( var i=0, len=arLen; i<len; ++i ){
|
31
|
+
newList = newList + '<option>' + options[i]+'</option>';
|
32
|
+
}
|
33
|
+
$('#order_delivery_time').html(newList);
|
34
|
+
} else {
|
35
|
+
$('#order_delivery_time').html("<option>No deliveries available on this date</option>");
|
36
|
+
}
|
37
|
+
};
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
$(document).ready(function() {
|
42
|
+
var deliveryOptions = new SpreeDeliveryOptions();
|
43
|
+
deliveryOptions.initializeDeliveryTimeSelect();
|
44
|
+
});
|
@@ -11,11 +11,17 @@ Spree::Order.class_eval do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def valid_delivery_date?
|
14
|
+
|
14
15
|
self.errors[:delivery_date] << 'cannot be blank' unless self.delivery_date
|
15
16
|
|
16
17
|
if self.delivery_date
|
17
18
|
self.errors[:delivery_date] << 'cannot be today or in the past' if self.delivery_date <= Date.today
|
18
19
|
|
20
|
+
options = week_day_options(self.delivery_date)
|
21
|
+
unless options
|
22
|
+
self.errors[:delivery_date] << "is not available on the selected week day."
|
23
|
+
end
|
24
|
+
|
19
25
|
cutoff_time = Time.now.change(hour: SpreeDeliveryOptions::Config.delivery_cut_off_hour)
|
20
26
|
if self.delivery_date == Date.tomorrow && Time.now > cutoff_time
|
21
27
|
self.errors[:delivery_date] << "cannot be tomorrow if the order is created after #{SpreeDeliveryOptions::Config.delivery_cut_off_hour}"
|
@@ -26,16 +32,28 @@ Spree::Order.class_eval do
|
|
26
32
|
end
|
27
33
|
|
28
34
|
def valid_delivery_time?
|
35
|
+
return unless self.delivery_date
|
36
|
+
|
29
37
|
self.errors[:delivery_time] << 'cannot be blank' unless self.delivery_time
|
30
38
|
|
31
39
|
if self.delivery_time
|
32
|
-
|
33
|
-
self.errors[:delivery_time] << 'is invalid' unless delivery_time_options.values.include?(self.delivery_time)
|
40
|
+
self.errors[:delivery_time] << 'is invalid' unless (week_day_options(self.delivery_date) && week_day_options(self.delivery_date).include?(self.delivery_time))
|
34
41
|
end
|
35
42
|
|
36
43
|
self.errors[:delivery_time].empty? ? true : false
|
37
44
|
end
|
38
45
|
|
46
|
+
private
|
47
|
+
|
48
|
+
def week_day_options(date)
|
49
|
+
week_day = date.strftime("%A")
|
50
|
+
delivery_options[week_day.downcase]
|
51
|
+
end
|
52
|
+
|
53
|
+
def delivery_options
|
54
|
+
@delivery_options ||= JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)
|
55
|
+
end
|
56
|
+
|
39
57
|
end
|
40
58
|
|
41
59
|
Spree::PermittedAttributes.checkout_attributes << :delivery_date
|
@@ -3,10 +3,13 @@
|
|
3
3
|
#delivery_date
|
4
4
|
.field
|
5
5
|
= form.label :delivery_date, "Delivery Date"
|
6
|
-
= form.
|
6
|
+
= form.date_field :delivery_date
|
7
7
|
.field
|
8
8
|
= form.label :delivery_time, "Delivery Time"
|
9
|
-
= form.select :delivery_time, JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)
|
9
|
+
= form.select :delivery_time, JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)["monday"]
|
10
|
+
|
11
|
+
.delivery-time-options{data: SpreeDeliveryOptions::Config.delivery_time_options}
|
12
|
+
|
10
13
|
%h5.stock-delivery-instructions-title
|
11
14
|
Delivery Instructions/Comments
|
12
15
|
#delivery_instructions
|
@@ -2,7 +2,8 @@ module SpreeDeliveryOptions
|
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < Rails::Generators::Base
|
4
4
|
|
5
|
-
def add_javascripts
|
5
|
+
def add_javascripts
|
6
|
+
append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_delivery_options\n"
|
6
7
|
end
|
7
8
|
|
8
9
|
def add_stylesheets
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SpreeDeliveryOptions
|
2
2
|
class Configuration < Spree::Preferences::Configuration
|
3
3
|
preference :delivery_cut_off_hour, :integer, default: 12
|
4
|
-
preference :delivery_time_options, :string, default: {
|
4
|
+
preference :delivery_time_options, :string, default: {monday: ['Between 6am-8am']}.to_json
|
5
5
|
end
|
6
6
|
end
|
data/spec/models/order_spec.rb
CHANGED
@@ -4,15 +4,58 @@ describe Spree::Order do
|
|
4
4
|
|
5
5
|
let(:order){Spree::Order.new}
|
6
6
|
|
7
|
-
|
7
|
+
before :each do
|
8
|
+
SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['Between 6-7am']}.to_json
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'delivery instructions' do
|
12
|
+
|
13
|
+
it 'should accept valid delivery instructions' do
|
14
|
+
order.delivery_instructions = "This is awesome"
|
15
|
+
order.valid_delivery_instructions?.should be_true
|
16
|
+
order.errors[:delivery_instructions].should be_empty
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should not accept delivery instructions that are too long' do
|
20
|
+
order.delivery_instructions = "A" * 501
|
21
|
+
order.valid_delivery_instructions?.should be_false
|
22
|
+
order.errors[:delivery_instructions].should_not be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "delivery options" do
|
8
28
|
|
9
|
-
describe
|
29
|
+
describe "basic validations" do
|
10
30
|
|
11
31
|
it 'should require delivery date' do
|
12
32
|
order.valid_delivery_date?.should == false
|
13
33
|
order.errors[:delivery_date].should_not be_empty
|
14
34
|
end
|
15
35
|
|
36
|
+
it 'should require delivery time' do
|
37
|
+
order.delivery_date = Date.today
|
38
|
+
|
39
|
+
order.valid_delivery_time?.should == false
|
40
|
+
order.errors[:delivery_time].should_not be_empty
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should require a valid option for delivery time' do
|
44
|
+
order.delivery_date = Date.today
|
45
|
+
|
46
|
+
order.delivery_time = 'crazy times!'
|
47
|
+
order.valid_delivery_time?.should == false
|
48
|
+
order.errors[:delivery_time].should_not be_empty
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "validating the cut off hour" do
|
54
|
+
|
55
|
+
before :each do
|
56
|
+
SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['Between 6-7am']}.to_json
|
57
|
+
end
|
58
|
+
|
16
59
|
it 'should not be valid if delivery date is in the past' do
|
17
60
|
order.delivery_date = Date.yesterday
|
18
61
|
order.valid_delivery_date?.should == false
|
@@ -26,76 +69,72 @@ describe Spree::Order do
|
|
26
69
|
end
|
27
70
|
|
28
71
|
it 'should not be valid if delivery date is tomorrow and it is past the cutoff time' do
|
29
|
-
time_now = DateTime.parse("
|
72
|
+
time_now = DateTime.parse("17/11/2013 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour}:01 +1100")
|
30
73
|
Timecop.freeze(time_now)
|
31
74
|
|
32
|
-
order.delivery_date = '
|
75
|
+
order.delivery_date = '18/11/2013'
|
33
76
|
order.valid_delivery_date?.should == false
|
34
77
|
order.errors[:delivery_date].should_not be_empty
|
35
78
|
Timecop.return
|
36
79
|
end
|
37
80
|
|
38
81
|
it 'should be valid if delivery date is tomorrow but is before the cutoff time' do
|
39
|
-
time_now = DateTime.parse("
|
82
|
+
time_now = DateTime.parse("17/11/2013 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour-1}:59 +1100")
|
40
83
|
Timecop.freeze(time_now)
|
41
84
|
|
42
|
-
order.delivery_date = '
|
85
|
+
order.delivery_date = '18/11/2013'
|
43
86
|
order.valid_delivery_date?
|
44
87
|
order.errors[:delivery_date].should be_empty
|
45
88
|
Timecop.return
|
46
89
|
end
|
47
90
|
|
48
|
-
|
49
|
-
time_now = DateTime.parse("20/11/2013 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour+1}:30 +1100")
|
50
|
-
Timecop.freeze(time_now)
|
91
|
+
end
|
51
92
|
|
52
|
-
|
53
|
-
|
93
|
+
describe "validating the week day" do
|
94
|
+
|
95
|
+
before :each do
|
96
|
+
SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['Between 6-7am']}.to_json
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should allow delivery time to be in a valid delivery day' do
|
100
|
+
order.delivery_date = DateTime.now.next_week.next_day(0)
|
101
|
+
order.valid_delivery_date?#.should == true
|
54
102
|
order.errors[:delivery_date].should be_empty
|
55
|
-
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should not allow delivery time to be in a non delivery day' do
|
106
|
+
order.delivery_date = DateTime.now.next_week.next_day(1)
|
107
|
+
order.valid_delivery_date?.should == false
|
108
|
+
order.errors[:delivery_date].should_not be_empty
|
56
109
|
end
|
57
110
|
|
58
111
|
end
|
59
112
|
|
60
|
-
describe
|
113
|
+
describe "validating delivery time in specific week day" do
|
61
114
|
|
62
|
-
|
63
|
-
delivery_time_options =
|
64
|
-
order.delivery_time = delivery_time_options["early_morning"]
|
65
|
-
order.valid_delivery_time?
|
66
|
-
order.errors[:delivery_time].should be_empty
|
115
|
+
before :each do
|
116
|
+
SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['Between 6-7am'], saturday: ['Between 9-12am']}.to_json
|
67
117
|
end
|
68
118
|
|
69
|
-
it 'should
|
70
|
-
order.
|
71
|
-
order.
|
72
|
-
end
|
119
|
+
it 'should not allow delivery time to be in an invalid slot for the delivery day' do
|
120
|
+
order.delivery_date = DateTime.now.next_week.next_day(5)
|
121
|
+
order.delivery_time = 'Between 6-7am'
|
73
122
|
|
74
|
-
it 'should require a valid option for delivery time' do
|
75
|
-
order.delivery_time = 'crazy times!'
|
76
123
|
order.valid_delivery_time?.should == false
|
77
124
|
order.errors[:delivery_time].should_not be_empty
|
78
125
|
end
|
79
126
|
|
80
|
-
|
127
|
+
it 'should allow delivery time to be in an valid slot for the delivery day' do
|
128
|
+
order.delivery_date = DateTime.now.next_week.next_day(5)
|
129
|
+
order.delivery_time = 'Between 9-12am'
|
81
130
|
|
82
|
-
|
83
|
-
|
84
|
-
it 'should accept valid delivery instructions' do
|
85
|
-
order.delivery_instructions = "This is awesome"
|
86
|
-
order.valid_delivery_instructions?.should be_true
|
87
|
-
order.errors[:delivery_instructions].should be_empty
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'should not accept delivery instructions that are too long' do
|
91
|
-
order.delivery_instructions = "A" * 501
|
92
|
-
order.valid_delivery_instructions?.should be_false
|
93
|
-
order.errors[:delivery_instructions].should_not be_empty
|
131
|
+
order.valid_delivery_time?.should == true
|
132
|
+
order.errors[:delivery_time].should be_empty
|
94
133
|
end
|
95
134
|
|
96
135
|
end
|
97
136
|
|
98
|
-
|
99
137
|
end
|
100
138
|
|
139
|
+
|
101
140
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_delivery_options
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francisco Trindade
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -191,6 +191,8 @@ files:
|
|
191
191
|
- README.md
|
192
192
|
- Rakefile
|
193
193
|
- Versionfile
|
194
|
+
- app/assets/javascripts/store/delivery_time_options.js
|
195
|
+
- app/assets/javascripts/store/spree_delivery_options.js
|
194
196
|
- app/assets/stylesheets/admin/order_details.scss
|
195
197
|
- app/assets/stylesheets/admin/spree_delivery_options.css
|
196
198
|
- app/assets/stylesheets/store/delivery_checkout.scss
|