solidus_subscription_boxes 0.0.6 → 0.0.7

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
  SHA1:
3
- metadata.gz: b7f6bff4c234fb7b885dde2d9ac3e516776602a8
4
- data.tar.gz: cdfad1c66c819b74ebc9679aa39043c162b3053a
3
+ metadata.gz: 777198967dcf84fbc05e24af7413e926c0d4f4e9
4
+ data.tar.gz: d433bbcd05a1b4c8ed33d264c750bfa91be67327
5
5
  SHA512:
6
- metadata.gz: 409869b545c2e810c654e450128a985804ccdd31c058f6703c5fc022a959bea80d72d330356dad8553fd9d3831522cc2575365d0f8182bfcf1e4b7b150b4cc47
7
- data.tar.gz: b2575ae580195b6cd9a51c007846cfdefd0c9dbc89d603f1da04f35f317a558b9bc7be3f835407fa80e05d77e73cdd8a0a32f30aba12eec94ab40b4066cc3fd1
6
+ metadata.gz: 8326e926d6e118e57381bcf25069eda78b5671b14b3d7671832fce17fa5757dbd5f03a1e34b17823882be9b215aab709dd422c17588bd407365af10fd2c04376
7
+ data.tar.gz: e983251c8b6481b0d951428f4000726c8b464347819a9c757d26c395a57342a2927964bc59a9094ba1c7f832f6d93aba2f8debb0772b0a617eb177f168c051a1
@@ -13,29 +13,39 @@ function subscriptionFormatDate(date) {
13
13
  return monthNames[monthIndex] + ' ' + day;
14
14
  }
15
15
 
16
+ $('.box-controls i').click(function(event) {
17
+ var value = parseInt($(this).siblings('input').val());
18
+ if(this.classList.contains('add')) {
19
+ value = Math.min(value + 1, 9);
20
+ } else {
21
+ value = Math.max(value - 1, 0);
22
+ }
23
+ $(this).siblings('input').val(value);
24
+
25
+
26
+ var numberOfMeals = function() {
27
+ var total = 0;
28
+ $('.box-controls input').each( function(element) {
29
+ total = total + parseInt(this.value);
30
+ });
31
+ return total;
32
+ }
16
33
 
17
- $('.meal-selection').click( function(event) {
18
34
  if( $('body.get_started').length > 0 ) {
19
35
  var submitButtonText = "Subscribe Now";
20
36
  } else {
21
37
  var submitButtonText = "Update My Order";
22
38
  }
23
39
 
24
- if( $('.meal-selection input:checked').length > 3 ) {
25
- alert("Only choose 3 meals");
26
- event.target.checked = false;
27
- event.preventDefault();
28
- }
29
-
30
- if( $('.meal-selection input:checked').length == 3 ) {
40
+ if( numberOfMeals() >= 3 ) {
31
41
  $('input[type=submit].meal-update').removeAttr('disabled');
32
42
  $('input[type=submit].meal-update').attr("value",submitButtonText);
33
43
  } else {
34
44
  $('input[type=submit].meal-update').attr("disabled","disabled");
35
- $('input[type=submit].meal-update').attr("value","Choose " + (3 - $('.meal-selection input:checked').length).toString() + " More");
45
+ $('input[type=submit].meal-update').attr("value","Choose " + (Math.max(3 - numberOfMeals(), 0)).toString() + " More");
36
46
  }
37
47
 
38
- $('.number_more_meals').text(3 - $('.meal-selection input:checked').length);
48
+ $('.number_more_meals').text(3 - numberOfMeals());
39
49
  });
40
50
 
41
51
  $(document).ajaxSuccess(function( event, xhr, settings ) {
@@ -20,15 +20,10 @@
20
20
  .flash.success {
21
21
  background-color: green;
22
22
  }
23
- .meal-selector .meal-selection, {
24
- .image {
25
- border: 3px transparent solid;
26
- cursor: pointer;
27
- &:hover {
28
- border: 3px $gray-500 solid;
29
- }
30
- }
31
- input:checked + .image {
32
- border: 3px $btn-box-shadow-color solid;
33
- }
34
- }
23
+ .meal-selector input{
24
+ width: 100px;
25
+ }
26
+ .box-controls i {
27
+ cursor: pointer;
28
+ }
29
+
@@ -14,6 +14,12 @@ module Spree
14
14
  if params[:box_preference_attributes]
15
15
  params[:box_preference_attributes].permit!
16
16
  @order.update_attributes(box_preference_attributes: params[:box_preference_attributes].to_hash)
17
+ @order.box_preference.preference.each do |key, value|
18
+ if value.to_i > 0 then
19
+ variant = Spree::Variant.find(key.to_i)
20
+ @order.contents.add(variant, value.to_i)
21
+ end
22
+ end
17
23
  end
18
24
  end
19
25
  end
@@ -19,7 +19,8 @@ module Spree
19
19
 
20
20
  must_change_subscriptions.each do |subscription|
21
21
  potential_variants = SolidusSubscriptionBoxes::SubscriptionPeriod.period_for_date(subscription.actionable_date).variants
22
- subscription.box_preference = SolidusSubscriptionBoxes::BoxPreference.new(preference: potential_variants.sample(3).map(&:id))
22
+ selected_preferences = Hash[potential_variants.sample(3).collect { |variant| [variant.id.to_s, 1.to_s] } ]
23
+ subscription.box_preference = SolidusSubscriptionBoxes::BoxPreference.new(preference: selected_preferences)
23
24
  end
24
25
  end
25
26
  end
@@ -7,5 +7,13 @@ module SolidusSubscriptionBoxes
7
7
  ""
8
8
  end
9
9
  end
10
+
11
+ def preferable_value(box_preference, variant_id)
12
+ if box_preference.present?
13
+ box_preference.preference.fetch(variant_id.to_s){ 0 }
14
+ else
15
+ 0
16
+ end
17
+ end
10
18
  end
11
19
  end
@@ -1,7 +1,7 @@
1
1
  module SolidusSubscriptionBoxes
2
2
  class BoxPreference < ApplicationRecord
3
3
  belongs_to :preferable, polymorphic: true
4
- serialize :preference, Array
4
+ serialize :preference, Hash
5
5
 
6
6
  def variants
7
7
  Spree::Variant.where(id: preference.map(&:to_i))
@@ -1,13 +1,15 @@
1
1
  <div class="meal-selector row row-centered">
2
2
  <%- box_variants.each do |variant| %>
3
3
  <div class="col-xs-12 col-md-4 col-centered text-center meal">
4
- <label class="meal-selection">
5
- <input class="d-none" type="checkbox" name="<%= preference_scope %>" value="<%= variant.id %>" <%= is_checked(preferable, variant) %>>
6
- <div class="image">
7
- <%= image_tag variant.display_image.attachment.url(:large) %>
8
- <h4><%= variant.name %></h4>
9
- </div>
10
- </label>
4
+ <div class="image">
5
+ <%= image_tag variant.display_image.attachment.url(:large) %>
6
+ <h4><%= variant.name %></h4>
7
+ </div>
8
+ <div class="box-controls display-4">
9
+ <i class="fa fa-3 fa-minus-circle remove" aria-hidden="true"></i>
10
+ <input class="border-0 col-4 text-right" type="number" name="<%= preference_scope %>[<%= variant.id %>]" value="<%= preferable_value(preferable.box_preference, variant.id) %>" readonly>
11
+ <i class="fa fa-3 fa-plus-circle add" aria-hidden="true"></i>
12
+ </div>
11
13
  </div>
12
14
  <% end %>
13
15
  </div>
@@ -8,7 +8,7 @@
8
8
  <%= render partial: 'solidus_subscription_boxes/subscription_boxes/box_variants',
9
9
  locals: {
10
10
  box_variants: SolidusSubscriptionBoxes::SubscriptionPeriod.period_for_date(subscription.actionable_date).variants,
11
- preference_scope: "subscription[box_preference_attributes][preference][]",
11
+ preference_scope: "subscription[box_preference_attributes][preference]",
12
12
  preferable: subscription
13
13
  }
14
14
  %>
@@ -34,7 +34,7 @@
34
34
  <h4 class="text-center">We update the menu seasonally to use the freshest ingredients</h4>
35
35
  <div class="pt-5">
36
36
  <%= form_for :order, url: '/orders/populate' do |f| %>
37
- <%= render partial: 'box_variants', locals: {box_variants: @box_variants, preference_scope: "box_preference_attributes[preference][]", preferable: f.object} %>
37
+ <%= render partial: 'box_variants', locals: {box_variants: @box_variants, preference_scope: "box_preference_attributes[preference]", preferable: f.object} %>
38
38
  <div class="row mt-5">
39
39
  <div class="col-12 content text-center">
40
40
  <%= hidden_field_tag :variant_id, @variant.id %>
@@ -1,3 +1,3 @@
1
1
  module SolidusSubscriptionBoxes
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_subscription_boxes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Jackson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2017-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus