spree_delivery_options 2.2.8 → 2.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -9
- data/app/assets/javascripts/spree/backend/delivery_time_options.js +23 -8
- data/app/assets/javascripts/spree/backend/spree_delivery_options.js +1 -0
- data/app/assets/javascripts/spree/frontend/delivery_time_options.js +25 -4
- data/app/assets/javascripts/spree/frontend/spree_delivery_options.js +1 -0
- data/app/helpers/spree_delivery_options/base_helper.rb +22 -23
- data/app/models/spree/order_decorator.rb +14 -45
- data/app/views/spree/admin/orders/delivery_options/edit.haml +3 -3
- data/app/views/spree/shared/_delivery_options.haml +1 -1
- data/lib/spree_delivery_options/configuration.rb +2 -2
- data/lib/spree_delivery_options/delivery_options_service.rb +49 -0
- data/spec/helpers/spree_delivery_options/base_helper_spec.rb +90 -22
- data/spec/models/order_spec.rb +101 -69
- data/spree_delivery_options.gemspec +1 -1
- metadata +3 -3
- data/spree_delivery_options-2.2.6.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f5a03d996f7cadc0ca14c68db26a316930675b2
|
4
|
+
data.tar.gz: 937419643b561f2e352ffe2f4d77d00528722f85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98a2fb5a4c6423a9f8757fbb068e0192bf77fa3c0470f797c6872d1ee29628673f7d1c906cd3cd8e953b13a654f7bb5ebd074b93f639b3a900841f12b19e7cf2
|
7
|
+
data.tar.gz: cb798df4efe3417f322e4a4eb89c1d93ad01f520d849832b0a2506f6df34019586e74c437a84cb6396e7dc61c3ca87cd87eaa983b1a21f1c4bb6dad06d947fb3
|
data/README.md
CHANGED
@@ -44,17 +44,25 @@ Configuration
|
|
44
44
|
Both the delivery cut off hour and the delivery time options can be configured in your application.rb file
|
45
45
|
|
46
46
|
config.after_initialize do
|
47
|
-
delivery_time_options =
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
delivery_time_options = [
|
48
|
+
{ 13:00 =>
|
49
|
+
{
|
50
|
+
monday: ["Before 6am", "9-12 am"],
|
51
|
+
tuesday: ["Before 6am", "9-12 am"]
|
52
|
+
}
|
53
|
+
}
|
54
|
+
].to_json
|
51
55
|
SpreeDeliveryOptions::Config.delivery_time_options = delivery_time_options
|
52
|
-
SpreeDeliveryOptions::Config.delivery_cut_off_hour = 12
|
53
56
|
end
|
54
57
|
|
55
58
|
The delivery options for any weekday can be overriden by specifying a date in dd/mm/yyyy format (i.e. for different times in public holidays).
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
delivery_time_options = [
|
61
|
+
{ 13:00 =>
|
62
|
+
{
|
63
|
+
"12/02/2014" => ["9-12am"],
|
64
|
+
monday: ["Before 6am", "9-12 am"],
|
65
|
+
tuesday: ["Before 6am", "9-12 am"]
|
66
|
+
}
|
67
|
+
}
|
68
|
+
].to_json
|
@@ -12,20 +12,35 @@ function SpreeDeliveryOptions() {
|
|
12
12
|
}
|
13
13
|
};
|
14
14
|
|
15
|
+
this.parseDeliveryOptions = function(deliveryDate) {
|
16
|
+
var deliveryTimeGroups = $.parseJSON($('.delivery-time-options').attr("data"));
|
17
|
+
var result;
|
18
|
+
var baselineTime = "00:01";
|
19
|
+
|
20
|
+
$.each(deliveryTimeGroups[0], function(index, value) {
|
21
|
+
if (baselineTime < index)
|
22
|
+
{
|
23
|
+
result = value;
|
24
|
+
return false;
|
25
|
+
}
|
26
|
+
});
|
27
|
+
return result;
|
28
|
+
};
|
29
|
+
|
15
30
|
this.update_delivery_time_options = function() {
|
16
|
-
var
|
31
|
+
var dateParts = []
|
32
|
+
if ($('#order_delivery_date').val().indexOf('/') !== -1) {
|
33
|
+
dateParts = $('#order_delivery_date').val().split('/')
|
34
|
+
} else {
|
35
|
+
dateParts = $('#order_delivery_date').val().split('-')
|
36
|
+
}
|
37
|
+
var deliveryDate = this.convertDateFormat(dateParts);
|
38
|
+
var deliveryTimeOptions = this.parseDeliveryOptions(deliveryDate);
|
17
39
|
|
18
40
|
if (deliveryTimeOptions){
|
19
41
|
weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
|
20
42
|
|
21
|
-
var dateParts = []
|
22
|
-
if ($('#order_delivery_date').val().indexOf('/') !== -1) {
|
23
|
-
dateParts = $('#order_delivery_date').val().split('/')
|
24
|
-
} else {
|
25
|
-
dateParts = $('#order_delivery_date').val().split('-')
|
26
|
-
}
|
27
43
|
|
28
|
-
var deliveryDate = this.convertDateFormat(dateParts);
|
29
44
|
var dayOptions = [];
|
30
45
|
if (deliveryTimeOptions[deliveryDate]) {
|
31
46
|
dayOptions = deliveryTimeOptions[deliveryDate];
|
@@ -17,14 +17,35 @@ function SpreeDeliveryOptions() {
|
|
17
17
|
});
|
18
18
|
};
|
19
19
|
|
20
|
+
this.parseDeliveryOptions = function(deliveryDate) {
|
21
|
+
var deliveryTimeGroups = $.parseJSON($('.delivery-time-options').attr("data"));
|
22
|
+
var result;
|
23
|
+
|
24
|
+
var baselineTime = moment().format('H:mm');
|
25
|
+
|
26
|
+
var tomorrow = moment().add('days', 1);
|
27
|
+
if (moment(deliveryDate, "DD-MM-YYYY").isAfter(tomorrow)) {
|
28
|
+
baselineTime = "00:01";
|
29
|
+
}
|
30
|
+
|
31
|
+
$.each(deliveryTimeGroups[0], function(index, value) {
|
32
|
+
if (baselineTime < index)
|
33
|
+
{
|
34
|
+
result = value;
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
});
|
38
|
+
return result;
|
39
|
+
};
|
40
|
+
|
20
41
|
this.update_delivery_time_options = function() {
|
21
|
-
|
42
|
+
var deliveryDate = $('#order_delivery_date').val();
|
43
|
+
var deliveryTimeOptions = this.parseDeliveryOptions(deliveryDate);
|
22
44
|
|
23
|
-
if (deliveryTimeOptions){
|
45
|
+
if (deliveryTimeOptions) {
|
24
46
|
weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
|
25
|
-
|
47
|
+
|
26
48
|
var dayOptions = [];
|
27
|
-
var deliveryDate = $('#order_delivery_date').val();
|
28
49
|
|
29
50
|
if (deliveryTimeOptions[deliveryDate]) {
|
30
51
|
dayOptions = deliveryTimeOptions[deliveryDate];
|
@@ -1,41 +1,40 @@
|
|
1
1
|
module SpreeDeliveryOptions
|
2
2
|
module BaseHelper
|
3
3
|
|
4
|
+
include ::SpreeDeliveryOptions::DeliveryOptionsService
|
5
|
+
|
4
6
|
def current_order_cutoff_time
|
5
|
-
return nil unless (current_order && current_order.delivery_date)
|
7
|
+
return nil unless (current_order && current_order.delivery_date && current_order.delivery_time)
|
6
8
|
|
7
|
-
cutoff_time = Time.zone.now.change(hour: SpreeDeliveryOptions::Config.delivery_cut_off_hour)
|
8
9
|
cutoff_date = current_order.delivery_date - 1.day
|
9
|
-
|
10
|
-
end
|
10
|
+
all_delivery_options = all_delivery_options_for_date(current_order.delivery_date)
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
possible_cutoff_times = all_delivery_options.select{ |opt|
|
13
|
+
opt.values.flatten.include?(current_order.delivery_time)
|
14
|
+
}.map{ |opt| opt.keys}.flatten rescue nil
|
14
15
|
|
15
|
-
|
16
|
-
return "" unless delivery_day
|
16
|
+
return nil if possible_cutoff_times.empty?
|
17
17
|
|
18
|
-
|
18
|
+
cutoff_time = DateTime.strptime(possible_cutoff_times.sort.last, "%H:%M").strftime("%l%P").strip
|
19
|
+
"#{cutoff_date.strftime('%A, %d %b')} before #{cutoff_time}"
|
19
20
|
end
|
20
21
|
|
21
|
-
def
|
22
|
-
|
22
|
+
def next_delivery_slot
|
23
|
+
current_time_string = Time.zone.now.strftime("%H:%M")
|
24
|
+
possible_delivery_day = Date.current + 1.day
|
23
25
|
|
24
|
-
|
26
|
+
next_delivery_slot_for(possible_delivery_day, current_time_string)
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
counter = 0
|
29
|
+
def next_delivery_slot_for(delivery_date, time_string, counter=0)
|
30
|
+
return "" if counter == 7 #break after cycling through the week
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
else
|
34
|
-
current_day = current_day + 1.day
|
35
|
-
counter = counter + 1
|
36
|
-
end
|
32
|
+
possible_delivery_options = delivery_options_for_date_and_time(delivery_date, time_string)
|
33
|
+
unless possible_delivery_options.empty?
|
34
|
+
return "#{delivery_date.strftime('%A').titleize} between #{possible_delivery_options.first}"
|
37
35
|
end
|
38
|
-
|
36
|
+
|
37
|
+
next_delivery_slot_for(delivery_date + 1.day, "00:01", counter + 1)
|
39
38
|
end
|
40
39
|
|
41
40
|
end
|
@@ -2,8 +2,9 @@ Spree::Order.class_eval do
|
|
2
2
|
require 'date'
|
3
3
|
require 'spree/order/checkout'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
include SpreeDeliveryOptions::DeliveryOptionsService
|
6
|
+
|
7
|
+
validate :valid_delivery_options?
|
7
8
|
|
8
9
|
def valid_delivery_instructions?
|
9
10
|
if self.delivery_instructions && self.delivery_instructions.length > 500
|
@@ -18,53 +19,24 @@ Spree::Order.class_eval do
|
|
18
19
|
self.errors[:delivery_date].empty? ? true : false
|
19
20
|
end
|
20
21
|
|
21
|
-
def valid_delivery_date?
|
22
|
-
if self.delivery_date && self.delivery_date_changed?
|
23
|
-
self.errors[:delivery_date] << 'cannot be today or in the past' if self.delivery_date <= Date.current
|
24
|
-
|
25
|
-
options = delivery_time_options(self.delivery_date)
|
26
|
-
unless options && !options.empty?
|
27
|
-
self.errors[:delivery_date] << "is not available on the selected date."
|
28
|
-
end
|
29
|
-
|
30
|
-
cutoff_time = Time.zone.now.change(hour: SpreeDeliveryOptions::Config.delivery_cut_off_hour)
|
31
|
-
if self.delivery_date == (Date.current + 1.day) && Time.zone.now > (cutoff_time + 15.minutes)
|
32
|
-
self.errors[:delivery_date] << "cannot be tomorrow if the order is created after 1pm"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
self.errors[:delivery_date].empty? ? true : false
|
37
|
-
end
|
38
|
-
|
39
22
|
def delivery_time_present?
|
40
23
|
self.errors[:delivery_time] << 'cannot be blank' unless self.delivery_time
|
41
24
|
self.errors[:delivery_time].empty? ? true : false
|
42
25
|
end
|
43
26
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
self.errors[:delivery_time] << 'cannot be blank' unless self.delivery_time
|
27
|
+
def valid_delivery_options?
|
28
|
+
if (self.delivery_date && self.delivery_date_changed?) && (self.delivery_time && self.delivery_time_changed?)
|
29
|
+
self.errors[:delivery_date] << 'cannot be today or in the past' if self.delivery_date <= Date.current
|
48
30
|
|
49
|
-
|
50
|
-
|
31
|
+
options = current_delivery_options_for_date(self.delivery_date)
|
32
|
+
if options && !options.empty?
|
33
|
+
self.errors[:delivery_time] << 'is invalid' unless options.include?(self.delivery_time)
|
34
|
+
else
|
35
|
+
self.errors[:delivery_date] << "is not available on the selected date."
|
36
|
+
end
|
51
37
|
end
|
52
38
|
|
53
|
-
self.errors[:delivery_time].empty? ? true : false
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def delivery_time_options(date)
|
59
|
-
date_string = date.strftime("%d/%m/%Y")
|
60
|
-
return delivery_options[date_string] if delivery_options[date_string]
|
61
|
-
|
62
|
-
week_day = date.strftime("%A")
|
63
|
-
delivery_options[week_day.downcase]
|
64
|
-
end
|
65
|
-
|
66
|
-
def delivery_options
|
67
|
-
@delivery_options ||= JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)
|
39
|
+
(self.errors[:delivery_date].empty? && self.errors[:delivery_time].empty?) ? true : false
|
68
40
|
end
|
69
41
|
|
70
42
|
end
|
@@ -76,8 +48,5 @@ Spree::PermittedAttributes.checkout_attributes << :delivery_instructions
|
|
76
48
|
Spree::Order.state_machine.before_transition :to => :payment, :do => :valid_delivery_instructions?
|
77
49
|
|
78
50
|
Spree::Order.state_machine.before_transition :to => :payment, :do => :delivery_date_present?
|
79
|
-
Spree::Order.state_machine.before_transition :to => :payment, :do => :valid_delivery_date?
|
80
|
-
|
81
51
|
Spree::Order.state_machine.before_transition :to => :payment, :do => :delivery_time_present?
|
82
|
-
Spree::Order.state_machine.before_transition :to => :payment, :do => :
|
83
|
-
|
52
|
+
Spree::Order.state_machine.before_transition :to => :payment, :do => :valid_delivery_options?
|
@@ -23,10 +23,10 @@
|
|
23
23
|
= f.label :delivery_date, "Delivery Date"
|
24
24
|
= f.text_field :delivery_date, class: "datepicker"
|
25
25
|
.field
|
26
|
-
- delivery_options = JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)
|
26
|
+
- delivery_options = JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)
|
27
27
|
.selected-delivery-time{data: @order.delivery_time}
|
28
|
-
|
29
|
-
= f.select :delivery_time,
|
28
|
+
= f.label :delivery_time, "Delivery Time"
|
29
|
+
= f.select :delivery_time, []
|
30
30
|
.field
|
31
31
|
= f.label :delivery_instructions, "Delivery Instructions"
|
32
32
|
= f.text_area :delivery_instructions, class: 'fullwidth'
|
@@ -22,7 +22,7 @@
|
|
22
22
|
= form.text_field :delivery_date, value: (l(order.delivery_date) rescue l(Date.current + 1))
|
23
23
|
.field
|
24
24
|
= form.label :delivery_time, "Delivery Time"
|
25
|
-
= form.select :delivery_time,
|
25
|
+
= form.select :delivery_time, current_delivery_options_for_date(Date.tomorrow)
|
26
26
|
.field
|
27
27
|
= form.submit "Set Delivery Time"
|
28
28
|
.delivery-time-options{data: SpreeDeliveryOptions::Config.delivery_time_options}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SpreeDeliveryOptions
|
2
2
|
class Configuration < Spree::Preferences::Configuration
|
3
|
-
preference :
|
4
|
-
preference :delivery_time_options, :string, default: {monday: ['Between
|
3
|
+
preference :delivery_cut_off_time, :string, default: [{cutoff_time: "13:15", id: :morning}, {cutoff_time: "23:59", id: :evening}].to_json
|
4
|
+
preference :delivery_time_options, :string, default: {morning: {monday: ['Between 6-7am']}, evening: {monday: ['6pm to 7:30pm']}}.to_json
|
5
5
|
preference :show_homepage_form, :boolean, default: true
|
6
6
|
end
|
7
7
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module SpreeDeliveryOptions
|
2
|
+
module DeliveryOptionsService
|
3
|
+
|
4
|
+
private
|
5
|
+
|
6
|
+
def current_delivery_options_for_date(delivery_date)
|
7
|
+
if delivery_date > (Date.current + 1.day)
|
8
|
+
delivery_options_for_date_and_time(delivery_date, "00:01")
|
9
|
+
else
|
10
|
+
delivery_options_for_date_and_time(delivery_date, Time.zone.now.strftime("%H:%M"))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def delivery_options_for_date_and_time(delivery_date, time_string)
|
15
|
+
current_delivery_options = delivery_options_for_time(time_string)
|
16
|
+
|
17
|
+
date_string = delivery_date.strftime("%d/%m/%Y")
|
18
|
+
return current_delivery_options[date_string] if current_delivery_options[date_string]
|
19
|
+
|
20
|
+
week_day = delivery_date.strftime("%A")
|
21
|
+
current_delivery_options[week_day.downcase] || []
|
22
|
+
end
|
23
|
+
|
24
|
+
def all_delivery_options_for_date(delivery_date)
|
25
|
+
all_options = []
|
26
|
+
date_string = delivery_date.strftime("%d/%m/%Y")
|
27
|
+
week_day = delivery_date.strftime("%A").downcase
|
28
|
+
|
29
|
+
delivery_groups.each do |cutoff_time, options|
|
30
|
+
if options[date_string]
|
31
|
+
all_options << {cutoff_time => options[date_string]}
|
32
|
+
elsif options[week_day]
|
33
|
+
all_options << {cutoff_time => options[week_day]}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
all_options
|
37
|
+
end
|
38
|
+
|
39
|
+
def delivery_options_for_time(order_time_string)
|
40
|
+
delivery_groups.each{|cutoff_time, options| return options if order_time_string < cutoff_time}
|
41
|
+
{}
|
42
|
+
end
|
43
|
+
|
44
|
+
def delivery_groups
|
45
|
+
@delivery_groups = JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)[0] || []
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -2,6 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SpreeDeliveryOptions::BaseHelper do
|
4
4
|
|
5
|
+
|
5
6
|
describe 'current order cutoff time' do
|
6
7
|
|
7
8
|
let(:order){FactoryGirl.build(:order)}
|
@@ -15,18 +16,56 @@ describe SpreeDeliveryOptions::BaseHelper do
|
|
15
16
|
helper.current_order_cutoff_time.should be_nil
|
16
17
|
end
|
17
18
|
|
18
|
-
it 'should return nil if
|
19
|
+
it 'should return nil if current order has no delivery date' do
|
19
20
|
order.delivery_date = nil
|
20
21
|
helper.current_order_cutoff_time.should be_nil
|
21
22
|
end
|
22
23
|
|
23
|
-
it 'should return
|
24
|
-
|
24
|
+
it 'should return nil if current order has no delivery time' do
|
25
|
+
order.delivery_date = Date.parse('23/04/2014')
|
26
|
+
order.delivery_time = nil
|
27
|
+
helper.current_order_cutoff_time.should be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return nil if delivery time is invalid' do
|
25
31
|
order.delivery_date = Date.parse('23/04/2014')
|
32
|
+
order.delivery_time = "crazy!"
|
33
|
+
helper.current_order_cutoff_time.should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should return the correct delivery group cut off time depending on the delivery time' do
|
37
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{"13:15" => {monday: ['6am to 7:30am']}, "20:00" => {monday: ['6pm to 7:30pm']}}].to_json
|
38
|
+
|
39
|
+
order.delivery_date = Date.parse('21/04/2014')
|
40
|
+
order.delivery_time = '6pm to 7:30pm'
|
41
|
+
|
42
|
+
time_now = DateTime.parse("18/03/2013")
|
43
|
+
Timecop.freeze(time_now)
|
44
|
+
helper.current_order_cutoff_time.should == 'Sunday, 20 Apr before 8pm'
|
45
|
+
Timecop.return
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should consider overrides when establishing the cutoff time' do
|
49
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{"13:15" => {monday: ['6pm to 7:30pm']}, "20:00" => {"21/04/2014" => ["9am to 12am"], monday: ['6pm to 7:30pm']}}].to_json
|
50
|
+
|
51
|
+
order.delivery_date = Date.parse('21/04/2014')
|
52
|
+
order.delivery_time = '6pm to 7:30pm'
|
53
|
+
|
54
|
+
time_now = DateTime.parse("18/03/2013")
|
55
|
+
Timecop.freeze(time_now)
|
56
|
+
helper.current_order_cutoff_time.should == 'Sunday, 20 Apr before 1pm'
|
57
|
+
Timecop.return
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should return the latest one if time is in both' do
|
61
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{"13:15" => {monday: ['6pm to 7:30pm']}, "20:00" => {monday: ['6pm to 7:30pm']}}].to_json
|
26
62
|
|
27
|
-
|
63
|
+
order.delivery_date = Date.parse('21/04/2014')
|
64
|
+
order.delivery_time = '6pm to 7:30pm'
|
65
|
+
|
66
|
+
time_now = DateTime.parse("18/03/2013")
|
28
67
|
Timecop.freeze(time_now)
|
29
|
-
helper.current_order_cutoff_time.should == '
|
68
|
+
helper.current_order_cutoff_time.should == 'Sunday, 20 Apr before 8pm'
|
30
69
|
Timecop.return
|
31
70
|
end
|
32
71
|
|
@@ -34,36 +73,65 @@ describe SpreeDeliveryOptions::BaseHelper do
|
|
34
73
|
|
35
74
|
describe 'next delivery slot' do
|
36
75
|
|
37
|
-
|
38
|
-
SpreeDeliveryOptions::Config.delivery_time_options = {
|
39
|
-
|
40
|
-
|
76
|
+
before :each do
|
77
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{
|
78
|
+
"13:15" => {tuesday: ['6am to 7:30am'], wednesday: ['6am to 7:30am'], thursday: []},
|
79
|
+
"20:00" => {tuesday: ['6pm to 7:30pm']}
|
80
|
+
}].to_json
|
81
|
+
end
|
41
82
|
|
42
|
-
|
83
|
+
after :each do
|
43
84
|
Timecop.return
|
44
85
|
end
|
45
86
|
|
46
|
-
it 'should return
|
47
|
-
|
48
|
-
time_now = DateTime.parse("10/03/2014 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour+1}:00 +1100")
|
87
|
+
it 'should return first slot for tomorrow morning if its before cutoff time' do
|
88
|
+
time_now = DateTime.parse("10/03/2014 12:00 +1100")
|
49
89
|
Timecop.freeze(time_now)
|
50
90
|
|
51
|
-
helper.next_delivery_slot.should == '
|
52
|
-
|
91
|
+
helper.next_delivery_slot.should == 'Tuesday between 6am to 7:30am'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should return first slot for tomorrow evening if its before evening cutoff time' do
|
95
|
+
time_now = DateTime.parse("10/03/2014 14:00 +1100")
|
96
|
+
Timecop.freeze(time_now)
|
97
|
+
|
98
|
+
helper.next_delivery_slot.should == 'Tuesday between 6pm to 7:30pm'
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should consider overrides when getting cutoff time' do
|
102
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{
|
103
|
+
"13:15" => {tuesday: ['6am to 7:30am'], wednesday: ['6am to 7:30am'], thursday: []},
|
104
|
+
"20:00" => {"11/03/2014" => ['9am to 12am'], tuesday: ['6pm to 7:30pm']}
|
105
|
+
}].to_json
|
106
|
+
|
107
|
+
time_now = DateTime.parse("10/03/2014 14:00 +1100")
|
108
|
+
Timecop.freeze(time_now)
|
109
|
+
|
110
|
+
helper.next_delivery_slot.should == 'Tuesday between 9am to 12am'
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should return the day after tomorrow morning if its after evening cutoff time' do
|
114
|
+
time_now = DateTime.parse("10/03/2014 20:01 +1100")
|
115
|
+
Timecop.freeze(time_now)
|
116
|
+
|
117
|
+
helper.next_delivery_slot.should == 'Wednesday between 6am to 7:30am'
|
53
118
|
end
|
54
119
|
|
55
120
|
it 'should skip day if deliveries are not available' do
|
56
|
-
SpreeDeliveryOptions::Config.delivery_time_options = {
|
57
|
-
|
121
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{
|
122
|
+
"13:15" => {monday: ['6am to 7:30am'], tuesday: ['6am to 7:30am'], wednesday: ['6am to 7:30am'], thursday: []},
|
123
|
+
"20:00" => {"11/03/2014" => ['9am to 12am'], tuesday: ['6pm to 7:30pm']}
|
124
|
+
}].to_json
|
125
|
+
|
126
|
+
time_now = DateTime.parse("02/05/2014 14:00 +1100")
|
58
127
|
Timecop.freeze(time_now)
|
59
128
|
|
60
|
-
helper.next_delivery_slot.should == 'Monday between 6am
|
61
|
-
Timecop.return
|
129
|
+
helper.next_delivery_slot.should == 'Monday between 6am to 7:30am'
|
62
130
|
end
|
63
131
|
|
64
|
-
it 'should return nil if no delivery times are
|
65
|
-
SpreeDeliveryOptions::Config.delivery_time_options =
|
66
|
-
time_now = DateTime.parse("13/03/2014
|
132
|
+
it 'should return nil if no delivery times are available' do
|
133
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [].to_json
|
134
|
+
time_now = DateTime.parse("13/03/2014 12:00 +1100")
|
67
135
|
Timecop.freeze(time_now)
|
68
136
|
|
69
137
|
helper.next_delivery_slot.should == ''
|
data/spec/models/order_spec.rb
CHANGED
@@ -5,8 +5,8 @@ describe Spree::Order do
|
|
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
|
-
SpreeDeliveryOptions::Config.
|
8
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{monday: ['Between 6-7am']}].to_json
|
9
|
+
SpreeDeliveryOptions::Config.delivery_cut_off_time = "13:15"
|
10
10
|
end
|
11
11
|
|
12
12
|
describe 'valid_delivery_instructions' do
|
@@ -46,147 +46,179 @@ describe Spree::Order do
|
|
46
46
|
|
47
47
|
end
|
48
48
|
|
49
|
-
describe
|
49
|
+
describe 'delivery_time_present' do
|
50
|
+
|
51
|
+
it 'should require delivery time' do
|
52
|
+
order.delivery_date = Date.today
|
53
|
+
|
54
|
+
order.delivery_time_present?.should == false
|
55
|
+
order.errors[:delivery_time].should_not be_empty
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "valid_delivery_options?" do
|
50
61
|
|
51
62
|
before :each do
|
52
|
-
SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['Between 6-7am']}.to_json
|
63
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{"13:15" => {monday: ['Between 6-7am'], tuesday: ['Between 6-7am'], wednesday: ['Between 6-7am']}, "20:00" => {monday: ['6pm to 7:30pm']}}].to_json
|
53
64
|
end
|
54
65
|
|
55
66
|
it 'should not be valid if delivery date is in the past' do
|
56
67
|
order.delivery_date = Date.yesterday
|
57
|
-
order.
|
68
|
+
order.delivery_time = 'Between 6-7am'
|
69
|
+
order.valid_delivery_options?.should == false
|
58
70
|
order.errors[:delivery_date].should_not be_empty
|
59
71
|
end
|
60
72
|
|
61
73
|
it 'should not be valid if delivery date is today' do
|
62
74
|
order.delivery_date = Date.today
|
63
|
-
order.
|
75
|
+
order.delivery_time = 'Between 6-7am'
|
76
|
+
order.valid_delivery_options?.should == false
|
64
77
|
order.errors[:delivery_date].should_not be_empty
|
65
78
|
end
|
66
79
|
|
67
|
-
it 'should be valid if delivery date is tomorrow and it is
|
68
|
-
time_now = DateTime.parse("17/11/2013
|
80
|
+
it 'should be valid if delivery date is tomorrow morning and it is before the morning cutoff time' do
|
81
|
+
time_now = DateTime.parse("17/11/2013 13:14 +1100", "%d/%m/%Y %H:%M %z")
|
69
82
|
Timecop.freeze(time_now)
|
70
83
|
|
71
84
|
order.delivery_date = '18/11/2013'
|
72
|
-
order.
|
85
|
+
order.delivery_time = 'Between 6-7am'
|
86
|
+
|
87
|
+
order.valid_delivery_options?.should == true
|
73
88
|
order.errors[:delivery_date].should be_empty
|
74
89
|
Timecop.return
|
75
90
|
end
|
76
91
|
|
77
|
-
it 'should
|
78
|
-
time_now = DateTime.parse("17/11/2013
|
92
|
+
it 'should be valid if delivery date is tomorrow evening and it is before the evening cutoff time' do
|
93
|
+
time_now = DateTime.parse("17/11/2013 19:14 +1100", "%d/%m/%Y %H:%M %z")
|
79
94
|
Timecop.freeze(time_now)
|
80
95
|
|
81
96
|
order.delivery_date = '18/11/2013'
|
82
|
-
order.
|
83
|
-
order.errors[:delivery_date].should_not be_empty
|
84
|
-
Timecop.return
|
85
|
-
end
|
97
|
+
order.delivery_time = '6pm to 7:30pm'
|
86
98
|
|
87
|
-
|
88
|
-
time_now = DateTime.parse("17/11/2013 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour-1}:59 +1100")
|
89
|
-
Timecop.freeze(time_now)
|
90
|
-
|
91
|
-
order.delivery_date = '18/11/2013'
|
92
|
-
order.valid_delivery_date?
|
99
|
+
order.valid_delivery_options?.should == true
|
93
100
|
order.errors[:delivery_date].should be_empty
|
94
101
|
Timecop.return
|
95
102
|
end
|
96
103
|
|
97
|
-
|
98
|
-
|
99
|
-
|
104
|
+
it 'should not be valid if delivery date is tomorrow morning but is after the morning cutoff time' do
|
105
|
+
time_now = DateTime.parse("17/11/2013 13:16 +1100", "%d/%m/%Y %H:%M %z")
|
106
|
+
Timecop.freeze(time_now)
|
100
107
|
|
101
|
-
|
102
|
-
order.
|
108
|
+
order.delivery_date = '18/11/2013'
|
109
|
+
order.delivery_time = 'Between 6-7am'
|
103
110
|
|
104
|
-
order.
|
111
|
+
order.valid_delivery_options?.should == false
|
105
112
|
order.errors[:delivery_time].should_not be_empty
|
113
|
+
Timecop.return
|
106
114
|
end
|
107
115
|
|
108
|
-
|
116
|
+
it 'should not be valid if delivery date is tomorrow evening and it is after the evening cutoff time' do
|
117
|
+
time_now = DateTime.parse("17/11/2013 20:01 +1100", "%d/%m/%Y %H:%M %z")
|
118
|
+
Timecop.freeze(time_now)
|
109
119
|
|
110
|
-
|
120
|
+
order.delivery_date = '18/11/2013'
|
121
|
+
order.delivery_time = '6pm to 7:30pm'
|
111
122
|
|
112
|
-
|
113
|
-
|
123
|
+
order.valid_delivery_options?.should == false
|
124
|
+
order.errors[:delivery_date].should_not be_empty
|
125
|
+
Timecop.return
|
114
126
|
end
|
115
127
|
|
116
|
-
it 'should
|
117
|
-
|
128
|
+
it 'should be valid if delivery date is after tomorrow morning even when its after the morning cutoff time' do
|
129
|
+
time_now = DateTime.parse("17/11/2013 19:14 +1100", "%d/%m/%Y %H:%M %z")
|
130
|
+
Timecop.freeze(time_now)
|
118
131
|
|
119
|
-
order.
|
120
|
-
order.
|
121
|
-
order.errors[:delivery_time].should_not be_empty
|
122
|
-
end
|
132
|
+
order.delivery_date = '19/11/2013'
|
133
|
+
order.delivery_time = 'Between 6-7am'
|
123
134
|
|
124
|
-
|
125
|
-
order.delivery_date = DateTime.now.next_week.next_day(0)
|
126
|
-
order.valid_delivery_date?#.should == true
|
135
|
+
order.valid_delivery_options?.should == true
|
127
136
|
order.errors[:delivery_date].should be_empty
|
137
|
+
Timecop.return
|
128
138
|
end
|
129
139
|
|
130
|
-
|
131
|
-
order.delivery_date = DateTime.now.next_week.next_day(1)
|
132
|
-
order.valid_delivery_date?.should == false
|
133
|
-
order.errors[:delivery_date].should_not be_empty
|
134
|
-
end
|
140
|
+
context 'delivery time' do
|
135
141
|
|
136
|
-
|
142
|
+
before :each do
|
143
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{"13:15" => {monday: ['Between 6-7am']}, "20:00" => {monday: ['6pm to 7:30pm']}}].to_json
|
144
|
+
end
|
137
145
|
|
138
|
-
it 'should
|
139
|
-
|
146
|
+
it 'should require a valid option for delivery time' do
|
147
|
+
order.delivery_date = Date.today
|
140
148
|
|
141
|
-
|
149
|
+
order.delivery_time = 'crazy times!'
|
150
|
+
order.valid_delivery_options?.should == false
|
151
|
+
order.errors[:delivery_date].should_not be_empty
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should allow valid delivery time' do
|
155
|
+
time_now = DateTime.parse("05/04/2014 10:00 +1100", "%d/%m/%Y %H:%M %z")
|
142
156
|
Timecop.freeze(time_now)
|
143
157
|
|
144
|
-
order.delivery_date =
|
158
|
+
order.delivery_date = Date.parse('07/04/2014')
|
145
159
|
order.delivery_time = 'Between 6-7am'
|
160
|
+
|
161
|
+
order.valid_delivery_options?.should == true
|
162
|
+
Timecop.return
|
163
|
+
end
|
146
164
|
|
147
|
-
|
165
|
+
it 'should not allow invalid delivery time for the date' do
|
166
|
+
time_now = DateTime.parse("05/04/2014 10:00 +1100", "%d/%m/%Y %H:%M %z")
|
167
|
+
Timecop.freeze(time_now)
|
168
|
+
|
169
|
+
order.delivery_date = Date.parse('07/04/2014')
|
170
|
+
order.delivery_time = '6am to 7:30am'
|
171
|
+
|
172
|
+
order.valid_delivery_options?.should == false
|
148
173
|
order.errors[:delivery_time].should_not be_empty
|
149
174
|
Timecop.return
|
150
175
|
end
|
151
176
|
|
152
|
-
it 'should not allow
|
153
|
-
|
154
|
-
|
155
|
-
time_now = DateTime.parse("01/03/2014")
|
177
|
+
it 'should not allow date that has no delivery slots' do
|
178
|
+
time_now = DateTime.parse("05/04/2014 10:00 +1100", "%d/%m/%Y %H:%M %z")
|
156
179
|
Timecop.freeze(time_now)
|
157
180
|
|
158
|
-
order.delivery_date =
|
181
|
+
order.delivery_date = Date.parse('08/04/2014')
|
159
182
|
order.delivery_time = 'Between 6-7am'
|
160
|
-
|
161
|
-
order.
|
183
|
+
|
184
|
+
order.valid_delivery_options?.should == false
|
162
185
|
order.errors[:delivery_date].should_not be_empty
|
163
|
-
order.valid_delivery_time?.should == false
|
164
|
-
order.errors[:delivery_time].should_not be_empty
|
165
186
|
Timecop.return
|
166
187
|
end
|
167
188
|
|
168
189
|
end
|
169
190
|
|
170
|
-
|
191
|
+
context "overriding delivery day with specific date" do
|
171
192
|
|
172
193
|
before :each do
|
173
|
-
SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['Between 6-7am'], saturday: ['Between 9-12am']}.to_json
|
174
194
|
end
|
175
195
|
|
176
196
|
it 'should not allow delivery time to be in an invalid slot for the delivery day' do
|
177
|
-
|
197
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{"13:15" => {monday: ['Between 6-7am'], '03/03/2014' => ['Between 9-12am']}, "20:00" => {monday: ['6pm to 7:30pm']}}].to_json
|
198
|
+
|
199
|
+
time_now = DateTime.parse("01/03/2014 10:00 +1100", "%d/%m/%Y %H:%M %z")
|
200
|
+
Timecop.freeze(time_now)
|
201
|
+
|
202
|
+
order.delivery_date = Date.parse('03/03/2014')
|
178
203
|
order.delivery_time = 'Between 6-7am'
|
179
204
|
|
180
|
-
order.
|
205
|
+
order.valid_delivery_options?.should == false
|
181
206
|
order.errors[:delivery_time].should_not be_empty
|
207
|
+
Timecop.return
|
182
208
|
end
|
183
209
|
|
184
|
-
it 'should allow delivery time to be in
|
185
|
-
|
186
|
-
order.delivery_time = 'Between 9-12am'
|
210
|
+
it 'should not allow delivery time to be in date with empty options' do
|
211
|
+
SpreeDeliveryOptions::Config.delivery_time_options = [{"13:15" => {monday: ['Between 6-7am'], '03/03/2014' => []}, "20:00" => {monday: ['6pm to 7:30pm']}}].to_json
|
187
212
|
|
188
|
-
|
189
|
-
|
213
|
+
time_now = DateTime.parse("01/03/2014")
|
214
|
+
Timecop.freeze(time_now)
|
215
|
+
|
216
|
+
order.delivery_date = Date.parse('03/03/2014')
|
217
|
+
order.delivery_time = 'Between 6-7am'
|
218
|
+
|
219
|
+
order.valid_delivery_options?.should == false
|
220
|
+
order.errors[:delivery_date].should_not be_empty
|
221
|
+
Timecop.return
|
190
222
|
end
|
191
223
|
|
192
224
|
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.2.
|
4
|
+
version: 2.2.10
|
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-
|
11
|
+
date: 2014-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -294,13 +294,13 @@ files:
|
|
294
294
|
- lib/generators/spree_delivery_options/install/install_generator.rb
|
295
295
|
- lib/spree_delivery_options.rb
|
296
296
|
- lib/spree_delivery_options/configuration.rb
|
297
|
+
- lib/spree_delivery_options/delivery_options_service.rb
|
297
298
|
- lib/spree_delivery_options/engine.rb
|
298
299
|
- script/rails
|
299
300
|
- spec/controllers/spree/admin/orders/delivery_options_controller_spec.rb
|
300
301
|
- spec/helpers/spree_delivery_options/base_helper_spec.rb
|
301
302
|
- spec/models/order_spec.rb
|
302
303
|
- spec/spec_helper.rb
|
303
|
-
- spree_delivery_options-2.2.6.gem
|
304
304
|
- spree_delivery_options.gemspec
|
305
305
|
homepage:
|
306
306
|
licenses: []
|
Binary file
|