solidus_auction 0.0.1 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed967ff89e313e5a77ce9ad7074c006f24a894b87bab2384ed196875e8f66bd1
4
- data.tar.gz: d4161f99b72d9b3c01ad202a8f9f7b82216b5f88fc422a6f8e9d9fcff9812eb6
3
+ metadata.gz: 761923accc9ce42c7154c77cbbece12b5581ed71e7d2ae8dcf3d063c39801415
4
+ data.tar.gz: c684ceb4c43f4c9263ddb834cc99d1248a356fab79871f73e5039c2ed32e5cc7
5
5
  SHA512:
6
- metadata.gz: eddeb43728e17fc6d9f3a5928fb1afab5c46e4a895c3ba211f7b139ed9f19883df42dbbd7ddc56e03d380e006cc4ca6764f368aa8f85f44fef413ccfb7f18c84
7
- data.tar.gz: e28c54950a8b96150d41d293cf26ae6f2cfb44b642eebd774b62cdae813c9de4bde444e27952541527982ac994ac152157acb43ae5eb0d4d4370a2a5181394fe
6
+ metadata.gz: e202fef7df5da578fcfef50f50830137126568f20ab1921b9a7b1e3e540a1cf4192e0a379d2dd24e9e96d7bc029bfc0165880f8a55d438332362ebc29c3256ce
7
+ data.tar.gz: 23fbda34bad7cd37c1bb084589b6f22c9529652325931d52c4fae1a1f29f5ff85e624b235c1ba180c8e529ed5001ca16485238e8fba85730371e3e8386b67cac
@@ -4,4 +4,5 @@
4
4
  //= require spree/backend/product_autocomplete
5
5
  //= require countdown
6
6
  //= require spree/ends_in
7
+ //= require spree/checkout_in
7
8
  //= require local-time
@@ -0,0 +1,30 @@
1
+ $(document).ready(function() {
2
+ setInterval(updateCheckoutTimes, 1000);
3
+ });
4
+
5
+ function updateCheckoutTimes() {
6
+ var checkoutRemainings = $(".checkout-in")
7
+ if (checkoutRemainings.length > 0) {
8
+ $.each(checkoutRemainings, updateCheckoutTime);
9
+ }
10
+ }
11
+
12
+ function updateCheckoutTime(_, element) {
13
+ var $element = $(element);
14
+ var currentDatetime = new Date();
15
+ var dateTime = $element.data("auction-checkout-deadline");
16
+ if (currentDatetime > dateTime) {
17
+ var pretext = $($element.siblings()[0]);
18
+ pretext.addClass("green");
19
+ pretext.html("Complete");
20
+ $element.remove();
21
+ } else {
22
+ var countdownString = countdown(
23
+ dateTime,
24
+ null,
25
+ countdown.DAYS|countdown.HOURS|countdown.MINUTES|countdown.SECONDS,
26
+ 2
27
+ ).toString();
28
+ }
29
+ element.innerHTML = countdownString;
30
+ }
@@ -14,9 +14,9 @@ function updateTime(_, element) {
14
14
  var currentDatetime = new Date();
15
15
  var auctionEndDatetime = $element.data("auction-end-datetime");
16
16
  if (currentDatetime > auctionEndDatetime) {
17
- var pretext = $element.siblings()[0];
17
+ var pretext = $($element.siblings()[0]);
18
18
  pretext.addClass("green");
19
- pretext.innerHTML = "Complete";
19
+ pretext.html("Complete");
20
20
  $element.remove();
21
21
  } else {
22
22
  var countdownString = countdown(
@@ -5,4 +5,5 @@
5
5
  //= require countdown
6
6
  //= require spree/ends_in
7
7
  //= require spree/frontend/starts_in
8
+ //= require spree/checkout_in
8
9
  //= require spree/frontend/votes
@@ -37,7 +37,7 @@ class Spree::Admin::AuctionsController < Spree::Admin::ResourceController
37
37
  end
38
38
 
39
39
  def permitted_auction_attributes
40
- %i{id title description starting_datetime planned_end_datetime starting_price reserve_price bid_increment time_increment countdown product_id}
40
+ %i{id title description starting_datetime planned_end_datetime starting_price reserve_price bid_increment time_increment countdown product_id checkout_time_minutes}
41
41
  end
42
42
 
43
43
  def permitted_resource_params
@@ -8,6 +8,7 @@ class Spree::Auction < Spree::Base
8
8
  before_save :init_current_price, if: :new_record?
9
9
  before_save :set_current_end_datetime
10
10
  after_find :set_complete
11
+ after_find :check_for_deadline
11
12
 
12
13
  validates :title, presence: true
13
14
  validates :description, presence: true
@@ -51,8 +52,14 @@ class Spree::Auction < Spree::Base
51
52
  current_price >= reserve_price
52
53
  end
53
54
 
55
+ def order_complete?
56
+ if order
57
+ order.complete?
58
+ end
59
+ end
60
+
54
61
  def won?
55
- complete && reserve_met? && highest_bidder
62
+ true if complete && reserve_met? && highest_bidder
56
63
  end
57
64
 
58
65
  def started?
@@ -62,7 +69,9 @@ class Spree::Auction < Spree::Base
62
69
  end
63
70
 
64
71
  def order
65
- variant.orders.first
72
+ if variant
73
+ variant.orders.first
74
+ end
66
75
  end
67
76
 
68
77
  def in_progress?
@@ -70,7 +79,15 @@ class Spree::Auction < Spree::Base
70
79
  end
71
80
 
72
81
  def visible_bids
73
- bids.where(visible: true)
82
+ bids.visible
83
+ end
84
+
85
+ def checkout_deadline
86
+ current_end_datetime + checkout_time_minutes.minutes
87
+ end
88
+
89
+ def checkout_deadline_not_met?
90
+ Time.now > checkout_deadline
74
91
  end
75
92
 
76
93
  def visible_bids_in_chron_order
@@ -85,22 +102,34 @@ class Spree::Auction < Spree::Base
85
102
  current_end_datetime.to_f * 1000
86
103
  end
87
104
 
105
+ def checkout_deadline_as_float
106
+ checkout_deadline.to_f * 1000
107
+ end
108
+
88
109
  def starting_datetime_as_float
89
110
  starting_datetime.to_f * 1000
90
111
  end
91
112
 
92
113
  def accepted_bids
93
- bids.where(accepted: true)
114
+ bids.accepted
94
115
  end
95
116
 
96
117
  def accepted_bids_in_order
97
118
  accepted_bids.order("amount DESC")
98
119
  end
99
120
 
121
+ def accepted_not_delinquent_bids_in_order
122
+ accepted_bids.not_delinquent.order("amount DESC")
123
+ end
124
+
100
125
  def highest_bid
101
126
  accepted_bids_in_order.first
102
127
  end
103
128
 
129
+ def highest_bidder_bids
130
+ highest_bidder.bids.where(auction_id: id)
131
+ end
132
+
104
133
  def second_highest_bid
105
134
  accepted_bids_in_order.second
106
135
  end
@@ -148,6 +177,28 @@ class Spree::Auction < Spree::Base
148
177
  end
149
178
  end
150
179
 
180
+ def check_for_deadline
181
+ if won? && checkout_deadline_not_met? && !order_complete?
182
+ highest_bidder_bids.update_all(delinquent: true)
183
+ highest_bidder_order = highest_bidder.last_incomplete_spree_order
184
+ if highest_bidder_order
185
+ highest_bidder_order.contents.remove(variant, 1)
186
+ end
187
+
188
+ bid = accepted_not_delinquent_bids_in_order.first
189
+ if bid
190
+ self.highest_bidder = bid.bidder
191
+ self.current_price = bid.amount
192
+ self.current_end_datetime = checkout_deadline
193
+ save
194
+ add_winning_item_to_highest_bidder_cart
195
+ else
196
+ self.highest_bidder_id = nil
197
+ save
198
+ end
199
+ end
200
+ end
201
+
151
202
  def add_winning_item_to_highest_bidder_cart
152
203
  user = highest_bidder
153
204
  cart = get_user_cart(user)
@@ -9,6 +9,11 @@ class Spree::Bid < Spree::Base
9
9
  extend Spree::DisplayMoney
10
10
  money_methods :amount
11
11
 
12
+ scope :accepted, -> { where(accepted: true) }
13
+ scope :visible, -> { where(visible: true) }
14
+ scope :delinquent, -> { where(delinquent: true) }
15
+ scope :not_delinquent, -> { where(delinquent: false) }
16
+
12
17
  def is_autobid?
13
18
  !visible && accepted
14
19
  end
@@ -1,6 +1,6 @@
1
1
  Deface::Override.new(
2
2
  virtual_path: 'spree/admin/shared/_order_summary',
3
3
  name: :auction_links_to_order_info,
4
- insert_bottom: "[data-hook='admin_settings_sub_tabs']",
4
+ insert_bottom: ".additional-info",
5
5
  partial: 'spree/admin/shared/auction_links_to_order_info'
6
6
  )
@@ -88,7 +88,7 @@
88
88
  <%= f.field_container :countdown do %>
89
89
  <%= f.label :countdown, Spree.t("countdown_seconds") %>
90
90
  <%= f.field_hint :countdown %>
91
- <%= f.number_field :countdown, disable_on_complete(auction_complete, {in: seconds_limit}) %>
91
+ <%= f.number_field :countdown, disable_on_complete(auction_complete, {in: seconds_limit}) %>
92
92
  <%= f.error_message_on :countdown %>
93
93
  <% end %>
94
94
  </div>
@@ -101,6 +101,17 @@
101
101
  <%= f.error_message_on :time_increment %>
102
102
  <% end %>
103
103
  </div>
104
+
105
+ <% minutes_limit = 1..10080 %>
106
+ <div data-hook="admin_auction_form_checkout_time_minutes" class="left col-6">
107
+ <%= f.field_container :checkout_time_minutes do %>
108
+
109
+ <%= f.label :checkout_time_minutes%>
110
+ <%= f.field_hint :checkout_time_minutes%>
111
+ <%= f.number_field :checkout_time_minutes, disable_on_complete(auction_complete, {in: minutes_limit}) %>
112
+ <%= f.error_message_on :checkout_time_minutes%>
113
+ <% end %>
114
+ </div>
104
115
  </div>
105
116
  </div>
106
117
 
@@ -121,7 +132,6 @@
121
132
  <% if !@auction.complete && auction.started? %>
122
133
  <div data-hook="admin_auction_form_time_remaining">
123
134
  <%= f.field_container :current_end_datetime do %>
124
- <label for="current_end_datetime"><%= Spree.t("ends_in") %></label>
125
135
  <p class="fullwidth title">
126
136
  <%= render partial: 'spree/shared/ends_in', locals: { auction: @auction } %>
127
137
  </p>
@@ -129,7 +139,7 @@
129
139
  </div>
130
140
  <% end %>
131
141
 
132
- <div class="clear"></div>
142
+
133
143
  <% if @auction.current_end_datetime %>
134
144
  <div data-hook="admin_auction_form_available_on">
135
145
  <%= f.field_container :current_end_datetime do %>
@@ -141,7 +151,32 @@
141
151
  <% end %>
142
152
  </div>
143
153
  <% end %>
154
+ <div class="clear"></div>
155
+
156
+ <% if @auction.current_end_datetime %>
157
+ <div data-hook="admin_auction_form_available_on">
158
+ <%= f.field_container :current_end_datetime do %>
159
+ <div class="field" id="auction_checkout_deadline">
160
+ <label for="checkout_deadline_date"><%= Spree.t("checkout_deadline") %></label>
161
+ <p class="fullwidth title">
162
+ <%= local_time @auction.checkout_deadline %>
163
+ </p>
164
+ <% end %>
165
+ </div>
166
+ </div>
167
+ <% end %>
168
+
169
+ <% if auction.won? && !auction.order_complete? %>
170
+ <div data-hook="admin_auction_form_checkout_deadline">
171
+ <%= f.field_container :current_end_datetime do %>
172
+ <p class="fullwidth title">
173
+ <%= render partial: 'spree/shared/checkout_in', locals: { auction: @auction } %>
174
+ </p>
175
+ <% end %>
176
+ </div>
177
+ <% end %>
144
178
 
179
+ <div class="clear"></div>
145
180
  <div class="clear"></div>
146
181
 
147
182
  <% if highest_bidder = auction.highest_bidder %>
@@ -31,7 +31,7 @@
31
31
  <th><%= Spree.t("bids") %></th>
32
32
  <th><%= Spree.t("starting_datetime") %></th>
33
33
  <th><%= Spree.t("current_end_datetime") %></th>
34
- <th><%= Spree.t("ends_in") %></th>
34
+ <th><%= Spree.t("time_remaining") %></th>
35
35
  <th></th>
36
36
  </tr>
37
37
  </thead>
@@ -57,12 +57,18 @@
57
57
  <td><%= local_time(auction.starting_datetime) %></td>
58
58
  <td><%= local_time(auction.current_end_datetime) %></td>
59
59
  <td>
60
- <% if auction.complete %>
60
+ <% if auction.order_complete? %>
61
61
  <span class="pill pill-complete">
62
62
  <%= Spree.t("complete") %>
63
63
  </span>
64
- <% elsif auction.started? %>
64
+ <% elsif auction.won? && !auction.order_complete? %>
65
+ <%= render partial: 'spree/shared/checkout_in', locals: { auction: auction } %>
66
+ <% elsif !auction.complete && auction.started? %>
65
67
  <%= render partial: 'spree/shared/ends_in', locals: { auction: auction } %>
68
+ <% elsif auction.complete && auction.highest_bidder.nil? %>
69
+ <span class="pill pill-pending">
70
+ <%= Spree.t("no_highest_bidder") %>
71
+ </span>
66
72
  <% else %>
67
73
  <span class="pill pill-pending">
68
74
  <%= Spree.t("waiting_to_start") %>
@@ -41,32 +41,34 @@
41
41
  </span>
42
42
  </div>
43
43
  <%= render partial: 'spree/shared/votes', locals: { auction: @auction } %>
44
- <div>
45
- <span>
46
- <%= t("spree.min_bid") %>:
47
- </span>
48
- <span>
49
- <%= number_to_currency(min_bid, :unit => "$") %>
50
- </span>
51
- </div>
44
+ <% if !@auction.complete %>
45
+ <div>
46
+ <span>
47
+ <%= t("spree.min_bid") %>:
48
+ </span>
49
+ <span>
50
+ <%= number_to_currency(min_bid, :unit => "$") %>
51
+ </span>
52
+ </div>
53
+ <% end %>
52
54
  </div>
53
55
  <% if spree_current_user %>
54
- <% highest_bidder = @auction.highest_bidder_id == spree_current_user.id %>
56
+ <% is_highest_bidder = @auction.highest_bidder_id == spree_current_user.id %>
55
57
  <% else %>
56
- <% highest_bidder = false %>
58
+ <% is_highest_bidder = false %>
57
59
  <% end %>
58
60
  <% if @auction.complete %>
59
- <% if highest_bidder %>
61
+ <% if is_highest_bidder %>
60
62
  <h6 class="product-section-title green">
61
63
  <%= Spree.t("you_have_won_this_auction") %>
62
64
  </h6>
65
+ <%= render partial: 'spree/shared/checkout_in', locals: { auction: @auction } %>
63
66
  <h6 class="product-section-title">
64
67
  <%= Spree.t("view_order_or_checkout") %>:
65
68
  </h6>
66
69
  <%= render partial: 'spree/shared/auction_order_link', locals: { auction: @auction } %>
67
70
  <% end %>
68
71
  <% else %>
69
-
70
72
  <%= hidden_field_tag :auction_id, @auction.id %>
71
73
  <div class="add-to-cart">
72
74
  <%= number_field_tag :amount, min_bid, class: 'title', min: min_bid, step: 0.01, disabled: !@auction.in_progress? %>
@@ -54,12 +54,19 @@
54
54
  </td>
55
55
  <td><%= local_time(auction.current_end_datetime) %></td>
56
56
  <td>
57
- <% if auction.complete %>
57
+ <% is_highest_bidder = auction.highest_bidder_id == spree_current_user.id %>
58
+ <% if is_highest_bidder && auction.order_complete? %>
58
59
  <span class="green">
59
60
  <%= Spree.t("complete") %>
60
61
  </span>
62
+ <% elsif is_highest_bidder && auction.won? && !auction.order_complete? %>
63
+ <%= render partial: 'spree/shared/checkout_in', locals: { auction: auction } %>
61
64
  <% elsif auction.in_progress? %>
62
65
  <%= render partial: 'spree/shared/ends_in', locals: { auction: auction } %>
66
+ <% elsif auction.complete? %>
67
+ <span class="green">
68
+ <%= Spree.t("complete") %>
69
+ </span>
63
70
  <% end %>
64
71
  </td>
65
72
  <td>
@@ -0,0 +1,18 @@
1
+ <% if auction.won? && !auction.order_complete? %>
2
+ <% if auction.current_end_datetime %>
3
+ <span>
4
+ <%= Spree.t("checkout_in") %>
5
+ </span>
6
+ <span class="checkout-in red" data-auction-checkout-deadline=<%= auction.checkout_deadline_as_float %> >
7
+ <% if auction.won? %>
8
+ <% if auction.order_complete? %>
9
+ <span class="green">
10
+ <%= Spree.t("payment_complete") %>
11
+ </span>
12
+ <% else %>
13
+ <%= distance_of_time_in_words_to_now(auction.checkout_deadline) %>
14
+ <% end %>
15
+ <% end %>
16
+ </span>
17
+ <% end %>
18
+ <% end %>
@@ -16,7 +16,11 @@
16
16
  <td class="cart-item-description" data-hook="cart_item_description">
17
17
  <h4><%= link_to auction.title, auction %></h4>
18
18
  <span class="line-item-description" data-hook="line_item_description">
19
- <%= auction.description %>
19
+ <%= line_item_description_text(auction.description) %>
20
+ </span>
21
+ &nbsp;<br />
22
+ <span class="line-item-description" data-hook="line_item_checkout_deadline">
23
+ <%= render partial: 'spree/shared/checkout_in', locals: { auction: auction } %>
20
24
  </span>
21
25
  </td>
22
26
  <% end %>
@@ -15,6 +15,10 @@ en:
15
15
  starting_soon_hours: Starting Soon Hours
16
16
  ending_soon: Ending Soon
17
17
  ending_soon_hours: Ending Soon Hours
18
+ payment_complete: Payment Complete
19
+ checkout_in: Must checkout in
20
+ no_highest_bidder: No highest bidder
21
+ checkout_deadline: Checkout Deadline
18
22
  recently_completed: Recently Completed
19
23
  recently_completed_hours: Recently Completed Hours
20
24
  number_of_bids_to_show: Number of bids to show
@@ -52,6 +56,7 @@ en:
52
56
  complete: Complete
53
57
  auctions: Auctions
54
58
  ends_in: Ends in
59
+ time_remaining: Time Remaining
55
60
  ends_at: Ends at
56
61
  starting_datetime: Start
57
62
  current_end_datetime: End
@@ -74,3 +79,4 @@ en:
74
79
  bid_increment: When a bidder bids, they have to bid the current price + this amount in order to succesfully bid. For example, if the current price is $25.00 and bid increment is $2.50, the next successful bidder must bid $27.50 or more.
75
80
  time_increment: Number of seconds to increase the end of the auction when within countdown.
76
81
  end: This is different from "Planned End" because the "countdown" and "time increment" can change the originally chosen date and time.
82
+ checkout_time_minutes: The amount of time the successful bidder has to make payment on your auction. Default is 1 day (1440 minutes) and maximum is 1 week (10080 minutes). Make it as urgent as you want.
@@ -0,0 +1,5 @@
1
+ class AddCheckoutTimeMinutesToSpreeAuctions < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :spree_auctions, :checkout_time_minutes, :integer, default: 1440
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddDelinquentToSpreeBids < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :spree_bids, :delinquent, :boolean, default: false
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_auction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Gu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-11 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -249,6 +249,7 @@ files:
249
249
  - app/assets/javascripts/local-time.js
250
250
  - app/assets/javascripts/spree/backend/product_autocomplete.js
251
251
  - app/assets/javascripts/spree/backend/solidus_auction.js
252
+ - app/assets/javascripts/spree/checkout_in.js
252
253
  - app/assets/javascripts/spree/ends_in.js
253
254
  - app/assets/javascripts/spree/frontend/solidus_auction.js
254
255
  - app/assets/javascripts/spree/frontend/starts_in.js
@@ -317,6 +318,7 @@ files:
317
318
  - app/views/spree/shared/_auctions.html.erb
318
319
  - app/views/spree/shared/_auctions_link.html.erb
319
320
  - app/views/spree/shared/_auctions_table_show.html.erb
321
+ - app/views/spree/shared/_checkout_in.html.erb
320
322
  - app/views/spree/shared/_ends_in.html.erb
321
323
  - app/views/spree/shared/_image.html.erb
322
324
  - app/views/spree/shared/_line_item_delete.html.erb
@@ -341,6 +343,8 @@ files:
341
343
  - db/migrate/20180328233438_add_variant_id_to_auction.rb
342
344
  - db/migrate/20180410025053_acts_as_votable_migration.rb
343
345
  - db/migrate/20180410031333_add_cached_votes_to_spree_auctions.rb
346
+ - db/migrate/20180415163201_add_checkout_time_minutes_to_spree_auctions.rb
347
+ - db/migrate/20180417180042_add_delinquent_to_spree_bids.rb
344
348
  - lib/assets/javascripts/src/local-time/calendar_date.coffee
345
349
  - lib/assets/javascripts/src/local-time/config/i18n.coffee
346
350
  - lib/assets/javascripts/src/local-time/config/locale.coffee
@@ -361,7 +365,7 @@ files:
361
365
  - lib/solidus_auction/engine.rb
362
366
  - lib/solidus_auction/factories.rb
363
367
  - lib/solidus_auction/version.rb
364
- homepage: https://jeffreygu.com
368
+ homepage: https://github.com/jgujgu/solidus_auction
365
369
  licenses:
366
370
  - BSD-3-Clause
367
371
  metadata: {}