spree_delivery_options 2.1.13 → 2.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96f62bf3f5c41b394f42579a8290cef63b846cd8
4
- data.tar.gz: 1534e023208ded8a3327237703493e59cdef33e3
3
+ metadata.gz: 70decd42b26f74b7a0a7d84043020dbe632df58d
4
+ data.tar.gz: e17addd9a179aa381bd5bfd427f88dbda6321708
5
5
  SHA512:
6
- metadata.gz: 8cd00a4b89819be097cb7aa450e947b2a6bfdb471ef34c7588f93458dcf1cda15a92fdf27e40a75617c3b0343af244a6fa280b724c165820d7697a70eaf5ffb0
7
- data.tar.gz: a515e680c0543f933bc374758367662e37edfdbdbf3d3df75dfa1c56099fbea68dee269ccc9648d21e1bc91f194f385cc4b2ff6ad1c217f499683029c537504b
6
+ metadata.gz: c31efcc66ff517e21b6c7357551171040bbe451b2079c72d9cd0a3629f1adf216dcc210c8aa9713be8a3397e6dd38791cc8d8346423c2aa6183c8399efdc7a2b
7
+ data.tar.gz: 7eb69bacd16dbafe1aad5fcca17ce831967462a16f236daec2ba496422fd68f179d2d606fe568356395f0852c0a03831b61ab76aefd71f9c33f37ef2fcc45797
data/README.md CHANGED
@@ -51,3 +51,9 @@ Both the delivery cut off hour and the delivery time options can be configured i
51
51
  SpreeDeliveryOptions::Config.delivery_cut_off_hour = 12
52
52
  end
53
53
 
54
+ 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).
55
+
56
+ delivery_time_options = {
57
+ '02/02/2014' => ["Before 6am", "9-12 am"],
58
+ tuesday: ["Before 6am", "9-12 am"]
59
+ }.to_json
@@ -13,9 +13,9 @@ function SpreeDeliveryOptions() {
13
13
  };
14
14
 
15
15
  this.update_delivery_time_options = function() {
16
- delivery_time_options = $.parseJSON($('.delivery-time-options').attr("data"));
16
+ var deliveryTimeOptions = $.parseJSON($('.delivery-time-options').attr("data"));
17
17
 
18
- if (delivery_time_options){
18
+ if (deliveryTimeOptions){
19
19
  weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
20
20
 
21
21
  var dateParts = []
@@ -24,12 +24,28 @@ function SpreeDeliveryOptions() {
24
24
  } else {
25
25
  dateParts = $('#order_delivery_date').val().split('-')
26
26
  }
27
- day_index = new Date(dateParts[0], dateParts[1]-1, dateParts[2]).getDay();
28
- weekday = weekdays[day_index];
29
27
 
30
- day_options = delivery_time_options[weekday];
31
- this.populate_delivery_time(day_options);
28
+ var deliveryDate = this.convertDateFormat(dateParts);
29
+ var dayOptions = [];
30
+ if (deliveryTimeOptions[deliveryDate]) {
31
+ dayOptions = deliveryTimeOptions[deliveryDate];
32
+ } else {
33
+ dayIndex = new Date(dateParts[0], dateParts[1]-1, dateParts[2]).getDay();
34
+ weekday = weekdays[dayIndex];
35
+ dayOptions = deliveryTimeOptions[weekday];
36
+ }
37
+ this.populate_delivery_time(dayOptions);
38
+ }
39
+ };
40
+
41
+ this.convertDateFormat = function(dateParts) {
42
+ var day = dateParts[2];
43
+ var month = parseInt(dateParts[1]);
44
+ if (month < 10) {
45
+ month = '0' + month;
32
46
  }
47
+ var year = dateParts[0];
48
+ return '' + day + '/' + month + '/' + year;
33
49
  };
34
50
 
35
51
  this.populate_delivery_time = function(options) {
@@ -15,16 +15,24 @@ function SpreeDeliveryOptions() {
15
15
  };
16
16
 
17
17
  this.update_delivery_time_options = function() {
18
- delivery_time_options = $.parseJSON($('.delivery-time-options').attr("data"));
18
+ deliveryTimeOptions = $.parseJSON($('.delivery-time-options').attr("data"));
19
19
 
20
- if (delivery_time_options){
20
+ if (deliveryTimeOptions){
21
21
  weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
22
- var dateParts = $('#order_delivery_date').val().split('/')
23
- day_index = new Date(dateParts[2], dateParts[1]-1, dateParts[0]).getDay();
24
- weekday = weekdays[day_index];
25
-
26
- day_options = delivery_time_options[weekday];
27
- this.populate_delivery_time(day_options);
22
+
23
+ var dayOptions = [];
24
+ var deliveryDate = $('#order_delivery_date').val();
25
+
26
+ if (deliveryTimeOptions[deliveryDate]) {
27
+ dayOptions = deliveryTimeOptions[deliveryDate];
28
+ } else {
29
+ var dateParts = deliveryDate.split('/')
30
+ var dayIndex = new Date(dateParts[2], dateParts[1]-1, dateParts[0]).getDay();
31
+ weekday = weekdays[dayIndex];
32
+
33
+ dayOptions = deliveryTimeOptions[weekday];
34
+ }
35
+ this.populate_delivery_time(dayOptions);
28
36
  }
29
37
  };
30
38
 
@@ -17,13 +17,13 @@ Spree::Order.class_eval do
17
17
  if self.delivery_date
18
18
  self.errors[:delivery_date] << 'cannot be today or in the past' if self.delivery_date <= Date.today
19
19
 
20
- options = week_day_options(self.delivery_date)
20
+ options = delivery_time_options(self.delivery_date)
21
21
  unless options
22
22
  self.errors[:delivery_date] << "is not available on the selected week day."
23
23
  end
24
24
 
25
25
  cutoff_time = Time.now.change(hour: SpreeDeliveryOptions::Config.delivery_cut_off_hour)
26
- if self.delivery_date == Date.tomorrow && Time.now > cutoff_time
26
+ if self.delivery_date == Date.tomorrow && Time.now > (cutoff_time + 15.minutes)
27
27
  self.errors[:delivery_date] << "cannot be tomorrow if the order is created after 1pm"
28
28
  end
29
29
  end
@@ -37,7 +37,7 @@ Spree::Order.class_eval do
37
37
  self.errors[:delivery_time] << 'cannot be blank' unless self.delivery_time
38
38
 
39
39
  if 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))
40
+ self.errors[:delivery_time] << 'is invalid' unless (delivery_time_options(self.delivery_date) && delivery_time_options(self.delivery_date).include?(self.delivery_time))
41
41
  end
42
42
 
43
43
  self.errors[:delivery_time].empty? ? true : false
@@ -45,7 +45,10 @@ Spree::Order.class_eval do
45
45
 
46
46
  private
47
47
 
48
- def week_day_options(date)
48
+ def delivery_time_options(date)
49
+ date_string = date.strftime("%d/%m/%Y")
50
+ return delivery_options[date_string] if delivery_options[date_string]
51
+
49
52
  week_day = date.strftime("%A")
50
53
  delivery_options[week_day.downcase]
51
54
  end
@@ -80,8 +80,18 @@ describe Spree::Order do
80
80
  order.errors[:delivery_date].should_not be_empty
81
81
  end
82
82
 
83
- it 'should not be valid if delivery date is tomorrow and it is past the cutoff time' do
84
- time_now = DateTime.parse("17/11/2013 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour}:01 +1100")
83
+ it 'should be valid if delivery date is tomorrow and it is past the cutoff time by less than 15 min' do
84
+ time_now = DateTime.parse("17/11/2013 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour}:14 +1100")
85
+ Timecop.freeze(time_now)
86
+
87
+ order.delivery_date = '18/11/2013'
88
+ order.valid_delivery_date?.should == true
89
+ order.errors[:delivery_date].should be_empty
90
+ Timecop.return
91
+ end
92
+
93
+ it 'should not be valid if delivery date is tomorrow and it is past the cutoff time + 15 min' do
94
+ time_now = DateTime.parse("17/11/2013 #{SpreeDeliveryOptions::Config.delivery_cut_off_hour}:16 +1100")
85
95
  Timecop.freeze(time_now)
86
96
 
87
97
  order.delivery_date = '18/11/2013'
@@ -122,6 +132,26 @@ describe Spree::Order do
122
132
 
123
133
  end
124
134
 
135
+ describe "overriding delivery day with specific date" do
136
+
137
+ before :each do
138
+ SpreeDeliveryOptions::Config.delivery_time_options = {monday: ['Between 6-7am'], '03/03/2014' => ['Between 9-12am']}.to_json
139
+ end
140
+
141
+ it 'should not allow delivery time to be in an invalid slot for the delivery day' do
142
+ time_now = DateTime.parse("01/03/2014")
143
+ Timecop.freeze(time_now)
144
+
145
+ order.delivery_date = Date.parse('03/03/2014')
146
+ order.delivery_time = 'Between 6-7am'
147
+
148
+ order.valid_delivery_time?.should == false
149
+ order.errors[:delivery_time].should_not be_empty
150
+ Timecop.return
151
+ end
152
+
153
+ end
154
+
125
155
  describe "validating delivery time in specific week day" do
126
156
 
127
157
  before :each do
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'spree_delivery_options'
5
- s.version = '2.1.13'
5
+ s.version = '2.1.14'
6
6
  s.summary = 'Adds delivery date and time during checkout'
7
7
  s.description = ''
8
8
  s.required_ruby_version = '>= 2.0.0'
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.13
4
+ version: 2.1.14
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-03-05 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core