solidus_subscription_boxes 0.0.11 → 0.0.12
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 +4 -4
- data/LICENSE +29 -29
- data/README.md +26 -26
- data/Rakefile +47 -47
- data/app/assets/config/solidus_subscription_boxes_manifest.js +2 -2
- data/app/assets/javascripts/solidus_subscription_boxes/application.js +13 -13
- data/app/assets/javascripts/solidus_subscription_boxes/subscription_selection.js +64 -64
- data/app/assets/stylesheets/_solidus_subscription_boxes.scss +16 -16
- data/app/assets/stylesheets/solidus_subscription_boxes/subscription_box.css.scss +29 -29
- data/app/controllers/solidus_subscription_boxes/application_controller.rb +4 -4
- data/app/controllers/solidus_subscription_boxes/subscription_boxes_controller.rb +7 -6
- data/app/decorators/solidus_subscriptions/models/checkout/update_preference_decorator.rb +13 -13
- data/app/decorators/spree/controllers/api/v1/subscriptions/meal_preference_decorator.rb +20 -20
- data/app/decorators/spree/controllers/orders/meal_preference_decorator.rb +35 -35
- data/app/decorators/spree/controllers/users/set_box_preference_decorator.rb +31 -31
- data/app/decorators/spree/orders/preference_decorator.rb +14 -14
- data/app/decorators/spree/products/boxable_decorator.rb +15 -15
- data/app/decorators/spree/variants/subscription_period_decorator.rb +13 -13
- data/app/helpers/solidus_subscription_boxes/application_helper.rb +26 -19
- data/app/jobs/solidus_subscription_boxes/application_job.rb +4 -4
- data/app/mailers/solidus_subscription_boxes/application_mailer.rb +6 -6
- data/app/models/solidus_subscription_boxes/application_record.rb +5 -5
- data/app/models/solidus_subscription_boxes/box_preference.rb +10 -10
- data/app/models/solidus_subscription_boxes/subscription_period.rb +15 -15
- data/app/models/solidus_subscription_boxes/subscription_periods_variant.rb +6 -6
- data/app/overrides/views/admin_boxable_checkbox.rb +5 -5
- data/app/views/layouts/solidus_subscription_boxes/application.html.erb +14 -14
- data/app/views/solidus_subscription_boxes/subscription_boxes/_box_variants.html.erb +14 -14
- data/app/views/solidus_subscription_boxes/subscription_boxes/_manage.html.erb +39 -39
- data/app/views/solidus_subscription_boxes/subscription_boxes/get_started.html.erb +52 -52
- data/app/views/spree/admin/products/_boxable_checkbox.html.erb +26 -26
- data/app/views/spree/admin/variants/_boxable_checkbox.html.erb +8 -8
- data/config/routes.rb +4 -4
- data/db/migrate/20170609065436_create_solidus_subscription_boxes_box_preferences.rb +10 -10
- data/db/migrate/20170906015531_create_solidus_subscription_boxes_subscription_periods.rb +9 -9
- data/db/migrate/20170906021159_create_solidus_subscription_boxes_subscription_periods_variants.rb +10 -10
- data/db/migrate/20170919054537_add_boxable_to_spree_variants.rb +5 -5
- data/db/migrate/20170919063437_add_boxable_variant_id_to_solidus_subscription_boxes_subscription_periods.rb +5 -5
- data/lib/solidus_subscription_boxes.rb +4 -4
- data/lib/solidus_subscription_boxes/engine.rb +13 -13
- data/lib/solidus_subscription_boxes/version.rb +3 -3
- data/lib/tasks/solidus_subscription_boxes_tasks.rake +4 -4
- data/test/integration/navigation_test.rb +8 -8
- data/test/solidus_subscription_boxes_test.rb +7 -7
- data/test/test_helper.rb +21 -21
- metadata +3 -3
@@ -1,4 +1,4 @@
|
|
1
|
-
module SolidusSubscriptionBoxes
|
2
|
-
class ApplicationController < ActionController::Base
|
3
|
-
end
|
4
|
-
end
|
1
|
+
module SolidusSubscriptionBoxes
|
2
|
+
class ApplicationController < ActionController::Base
|
3
|
+
end
|
4
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
|
-
class SolidusSubscriptionBoxes::SubscriptionBoxesController < Spree::StoreController
|
2
|
-
def get_started
|
3
|
-
@variant = Spree::Product.find_by_slug(params[:product_id]).master
|
4
|
-
@box_variants = SolidusSubscriptionBoxes::SubscriptionPeriod.where(boxable_variant_id: @variant.id).current.variants
|
5
|
-
|
6
|
-
end
|
1
|
+
class SolidusSubscriptionBoxes::SubscriptionBoxesController < Spree::StoreController
|
2
|
+
def get_started
|
3
|
+
@variant = Spree::Product.find_by_slug(params[:product_id]).master
|
4
|
+
@box_variants = SolidusSubscriptionBoxes::SubscriptionPeriod.where(boxable_variant_id: @variant.id).current.variants
|
5
|
+
@order = current_order
|
6
|
+
end
|
7
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module SolidusSubscriptions
|
2
|
-
module Models
|
3
|
-
module Checkout
|
4
|
-
module UpdatePreferenceDecorator
|
5
|
-
def order
|
6
|
-
order = super
|
7
|
-
order.box_preference = subscription.box_preference unless order.box_preference.present?
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
1
|
+
module SolidusSubscriptions
|
2
|
+
module Models
|
3
|
+
module Checkout
|
4
|
+
module UpdatePreferenceDecorator
|
5
|
+
def order
|
6
|
+
order = super
|
7
|
+
order.box_preference = subscription.box_preference unless order.box_preference.present?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
14
|
SolidusSubscriptions::Checkout.prepend(SolidusSubscriptions::Models::Checkout::UpdatePreferenceDecorator)
|
@@ -1,21 +1,21 @@
|
|
1
|
-
module Spree
|
2
|
-
module Controllers
|
3
|
-
module Api
|
4
|
-
module V1
|
5
|
-
module Subscriptions
|
6
|
-
module MealPreferenceDecorator
|
7
|
-
def subscription_params
|
8
|
-
params.require(:subscription).permit(
|
9
|
-
line_items_attributes: line_item_attributes,
|
10
|
-
shipping_address_attributes: Spree::PermittedAttributes.address_attributes,
|
11
|
-
box_preference_attributes: {}
|
12
|
-
)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
1
|
+
module Spree
|
2
|
+
module Controllers
|
3
|
+
module Api
|
4
|
+
module V1
|
5
|
+
module Subscriptions
|
6
|
+
module MealPreferenceDecorator
|
7
|
+
def subscription_params
|
8
|
+
params.require(:subscription).permit(
|
9
|
+
line_items_attributes: line_item_attributes,
|
10
|
+
shipping_address_attributes: Spree::PermittedAttributes.address_attributes,
|
11
|
+
box_preference_attributes: {}
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
21
|
SolidusSubscriptions::Api::V1::SubscriptionsController.prepend(Spree::Controllers::Api::V1::Subscriptions::MealPreferenceDecorator)
|
@@ -1,35 +1,35 @@
|
|
1
|
-
module Spree
|
2
|
-
module Controllers
|
3
|
-
module Orders
|
4
|
-
module MealPreferenceDecorator
|
5
|
-
def self.prepended(base)
|
6
|
-
base.after_action(
|
7
|
-
:set_box_preference,
|
8
|
-
only: :populate
|
9
|
-
)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
def set_box_preference
|
14
|
-
line_item_ids = @order.line_items.map(&:id)
|
15
|
-
line_item_ids.each { |line_item_id|
|
16
|
-
@order.contents.remove_line_item(LineItem.find(line_item_id))
|
17
|
-
}
|
18
|
-
@order.reload
|
19
|
-
if params[:box_preference_attributes]
|
20
|
-
params[:box_preference_attributes].permit!
|
21
|
-
@order.update_attributes(box_preference_attributes: params[:box_preference_attributes].to_hash)
|
22
|
-
@order.box_preference.preference.each do |key, value|
|
23
|
-
if value.to_i > 0 then
|
24
|
-
variant = Spree::Variant.find(key.to_i)
|
25
|
-
@order.contents.add(variant, value.to_i)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
Spree::OrdersController.prepend(Spree::Controllers::Orders::MealPreferenceDecorator)
|
1
|
+
module Spree
|
2
|
+
module Controllers
|
3
|
+
module Orders
|
4
|
+
module MealPreferenceDecorator
|
5
|
+
def self.prepended(base)
|
6
|
+
base.after_action(
|
7
|
+
:set_box_preference,
|
8
|
+
only: [:populate, :update]
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def set_box_preference
|
14
|
+
line_item_ids = @order.line_items.map(&:id)
|
15
|
+
line_item_ids.each { |line_item_id|
|
16
|
+
@order.contents.remove_line_item(LineItem.find(line_item_id))
|
17
|
+
}
|
18
|
+
@order.reload
|
19
|
+
if params[:box_preference_attributes]
|
20
|
+
params[:box_preference_attributes].permit!
|
21
|
+
@order.update_attributes(box_preference_attributes: params[:box_preference_attributes].to_hash)
|
22
|
+
@order.box_preference.preference.each do |key, value|
|
23
|
+
if value.to_i > 0 then
|
24
|
+
variant = Spree::Variant.find(key.to_i)
|
25
|
+
@order.contents.add(variant, value.to_i)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Spree::OrdersController.prepend(Spree::Controllers::Orders::MealPreferenceDecorator)
|
@@ -1,31 +1,31 @@
|
|
1
|
-
module Spree
|
2
|
-
module Controllers
|
3
|
-
module Users
|
4
|
-
module SetBoxPreferenceDecorator
|
5
|
-
def self.prepended(base)
|
6
|
-
base.before_action(
|
7
|
-
:set_box_preferences,
|
8
|
-
only: :show
|
9
|
-
)
|
10
|
-
end
|
11
|
-
|
12
|
-
private
|
13
|
-
def set_box_preferences
|
14
|
-
@user.generate_spree_api_key! unless @user.spree_api_key
|
15
|
-
|
16
|
-
must_change_subscriptions = @user.subscriptions.find_all do |subscription|
|
17
|
-
subscription.box_preference.nil?
|
18
|
-
end
|
19
|
-
|
20
|
-
must_change_subscriptions.each do |subscription|
|
21
|
-
potential_variants = SolidusSubscriptionBoxes::SubscriptionPeriod.period_for_date(subscription.actionable_date).variants
|
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)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
Spree::UsersController.prepend(Spree::Controllers::Users::SetBoxPreferenceDecorator)
|
1
|
+
module Spree
|
2
|
+
module Controllers
|
3
|
+
module Users
|
4
|
+
module SetBoxPreferenceDecorator
|
5
|
+
def self.prepended(base)
|
6
|
+
base.before_action(
|
7
|
+
:set_box_preferences,
|
8
|
+
only: :show
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def set_box_preferences
|
14
|
+
@user.generate_spree_api_key! unless @user.spree_api_key
|
15
|
+
|
16
|
+
must_change_subscriptions = @user.subscriptions.find_all do |subscription|
|
17
|
+
subscription.box_preference.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
must_change_subscriptions.each do |subscription|
|
21
|
+
potential_variants = SolidusSubscriptionBoxes::SubscriptionPeriod.period_for_date(subscription.actionable_date).variants
|
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)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Spree::UsersController.prepend(Spree::Controllers::Users::SetBoxPreferenceDecorator)
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module Spree
|
2
|
-
module Orders
|
3
|
-
module PreferenceDecorator
|
4
|
-
def self.prepended(base)
|
5
|
-
base.has_one :box_preference, as: :preferable, class_name: 'SolidusSubscriptionBoxes::BoxPreference'
|
6
|
-
base.accepts_nested_attributes_for :box_preference
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
Spree::Order.prepend(Spree::Orders::PreferenceDecorator)
|
13
|
-
SolidusSubscriptions::Subscription.prepend(Spree::Orders::PreferenceDecorator)
|
14
|
-
SolidusSubscriptions::Installment.prepend(Spree::Orders::PreferenceDecorator)
|
1
|
+
module Spree
|
2
|
+
module Orders
|
3
|
+
module PreferenceDecorator
|
4
|
+
def self.prepended(base)
|
5
|
+
base.has_one :box_preference, as: :preferable, class_name: 'SolidusSubscriptionBoxes::BoxPreference'
|
6
|
+
base.accepts_nested_attributes_for :box_preference
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Spree::Order.prepend(Spree::Orders::PreferenceDecorator)
|
13
|
+
SolidusSubscriptions::Subscription.prepend(Spree::Orders::PreferenceDecorator)
|
14
|
+
SolidusSubscriptions::Installment.prepend(Spree::Orders::PreferenceDecorator)
|
@@ -1,15 +1,15 @@
|
|
1
|
-
module Spree
|
2
|
-
module Products
|
3
|
-
module BoxableDecorator
|
4
|
-
def self.prepended(klass)
|
5
|
-
klass.delegate :"boxable", :"boxable=", to: :find_or_build_master
|
6
|
-
klass.delegate :"boxed_subscription_periods_variants", to: :find_or_build_master
|
7
|
-
klass.delegate :"boxed_subscription_periods", to: :find_or_build_master
|
8
|
-
klass.delegate :"subscription_periods", to: :find_or_build_master
|
9
|
-
klass.accepts_nested_attributes_for :master
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
Spree::Product.prepend Spree::Products::BoxableDecorator
|
1
|
+
module Spree
|
2
|
+
module Products
|
3
|
+
module BoxableDecorator
|
4
|
+
def self.prepended(klass)
|
5
|
+
klass.delegate :"boxable", :"boxable=", to: :find_or_build_master
|
6
|
+
klass.delegate :"boxed_subscription_periods_variants", to: :find_or_build_master
|
7
|
+
klass.delegate :"boxed_subscription_periods", to: :find_or_build_master
|
8
|
+
klass.delegate :"subscription_periods", to: :find_or_build_master
|
9
|
+
klass.accepts_nested_attributes_for :master
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Spree::Product.prepend Spree::Products::BoxableDecorator
|
@@ -1,14 +1,14 @@
|
|
1
|
-
module Spree
|
2
|
-
module Variants
|
3
|
-
module SubscriptionPeriodsDecorator
|
4
|
-
def self.prepended(klass)
|
5
|
-
klass.has_many :boxed_subscription_periods_variants, foreign_key: :spree_variant_id, class_name: 'SolidusSubscriptionBoxes::SubscriptionPeriodsVariant'
|
6
|
-
klass.has_many :boxed_subscription_periods, through: :boxed_subscription_periods_variants, class_name: 'SolidusSubscriptionBoxes::SubscriptionPeriod', source: :subscription_period
|
7
|
-
klass.has_many :subscription_periods, foreign_key: :boxable_variant_id, class_name: 'SolidusSubscriptionBoxes::SubscriptionPeriod'
|
8
|
-
klass.accepts_nested_attributes_for :subscription_periods
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
1
|
+
module Spree
|
2
|
+
module Variants
|
3
|
+
module SubscriptionPeriodsDecorator
|
4
|
+
def self.prepended(klass)
|
5
|
+
klass.has_many :boxed_subscription_periods_variants, foreign_key: :spree_variant_id, class_name: 'SolidusSubscriptionBoxes::SubscriptionPeriodsVariant'
|
6
|
+
klass.has_many :boxed_subscription_periods, through: :boxed_subscription_periods_variants, class_name: 'SolidusSubscriptionBoxes::SubscriptionPeriod', source: :subscription_period
|
7
|
+
klass.has_many :subscription_periods, foreign_key: :boxable_variant_id, class_name: 'SolidusSubscriptionBoxes::SubscriptionPeriod'
|
8
|
+
klass.accepts_nested_attributes_for :subscription_periods
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
14
|
Spree::Variant.prepend Spree::Variants::SubscriptionPeriodsDecorator
|
@@ -1,19 +1,26 @@
|
|
1
|
-
module SolidusSubscriptionBoxes
|
2
|
-
module ApplicationHelper
|
3
|
-
def is_checked(preferable, variant)
|
4
|
-
if preferable.present? && preferable.box_preference.preference.map(&:to_i).include?(variant.id)
|
5
|
-
"checked"
|
6
|
-
else
|
7
|
-
""
|
8
|
-
end
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
module SolidusSubscriptionBoxes
|
2
|
+
module ApplicationHelper
|
3
|
+
def is_checked(preferable, variant)
|
4
|
+
if preferable.present? && preferable.box_preference.preference.map(&:to_i).include?(variant.id)
|
5
|
+
"checked"
|
6
|
+
else
|
7
|
+
""
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def preferable_value(box_preference, variant_id, order = nil)
|
12
|
+
if box_preference.present?
|
13
|
+
box_preference.preference.fetch(variant_id.to_s){ 0 }
|
14
|
+
elsif order.present?
|
15
|
+
line_item = order.line_items.detect{|li| li.variant_id == variant_id}
|
16
|
+
if line_item.present?
|
17
|
+
line_item.quantity
|
18
|
+
else
|
19
|
+
0
|
20
|
+
end
|
21
|
+
else
|
22
|
+
0
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module SolidusSubscriptionBoxes
|
2
|
-
class ApplicationJob < ActiveJob::Base
|
3
|
-
end
|
4
|
-
end
|
1
|
+
module SolidusSubscriptionBoxes
|
2
|
+
class ApplicationJob < ActiveJob::Base
|
3
|
+
end
|
4
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module SolidusSubscriptionBoxes
|
2
|
-
class ApplicationMailer < ActionMailer::Base
|
3
|
-
default from: 'from@example.com'
|
4
|
-
layout 'mailer'
|
5
|
-
end
|
6
|
-
end
|
1
|
+
module SolidusSubscriptionBoxes
|
2
|
+
class ApplicationMailer < ActionMailer::Base
|
3
|
+
default from: 'from@example.com'
|
4
|
+
layout 'mailer'
|
5
|
+
end
|
6
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module SolidusSubscriptionBoxes
|
2
|
-
class ApplicationRecord < ActiveRecord::Base
|
3
|
-
self.abstract_class = true
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module SolidusSubscriptionBoxes
|
2
|
+
class ApplicationRecord < ActiveRecord::Base
|
3
|
+
self.abstract_class = true
|
4
|
+
end
|
5
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module SolidusSubscriptionBoxes
|
2
|
-
class BoxPreference < ApplicationRecord
|
3
|
-
belongs_to :preferable, polymorphic: true
|
4
|
-
serialize :preference, Hash
|
5
|
-
|
6
|
-
def variants
|
7
|
-
Spree::Variant.where(id: preference.map(&:to_i))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module SolidusSubscriptionBoxes
|
2
|
+
class BoxPreference < ApplicationRecord
|
3
|
+
belongs_to :preferable, polymorphic: true
|
4
|
+
serialize :preference, Hash
|
5
|
+
|
6
|
+
def variants
|
7
|
+
Spree::Variant.where(id: preference.map(&:to_i))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
module SolidusSubscriptionBoxes
|
2
|
-
class SubscriptionPeriod < ApplicationRecord
|
3
|
-
has_many :subscription_periods_variants, foreign_key: :solidus_subscription_boxes_subscription_period_id, class_name: 'SolidusSubscriptionBoxes::SubscriptionPeriodsVariant'
|
4
|
-
has_many :variants, through: :subscription_periods_variants, class_name: 'Spree::Variant'
|
5
|
-
belongs_to :boxable_variant, class_name: 'Spree::Variant', foreign_key: 'boxable_variant_id'
|
6
|
-
|
7
|
-
def self.current
|
8
|
-
period_for_date(Date.today)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.period_for_date(date)
|
12
|
-
SubscriptionPeriod.where('start_date <= ?', date).order('start_date desc').first
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
1
|
+
module SolidusSubscriptionBoxes
|
2
|
+
class SubscriptionPeriod < ApplicationRecord
|
3
|
+
has_many :subscription_periods_variants, foreign_key: :solidus_subscription_boxes_subscription_period_id, class_name: 'SolidusSubscriptionBoxes::SubscriptionPeriodsVariant'
|
4
|
+
has_many :variants, through: :subscription_periods_variants, class_name: 'Spree::Variant'
|
5
|
+
belongs_to :boxable_variant, class_name: 'Spree::Variant', foreign_key: 'boxable_variant_id'
|
6
|
+
|
7
|
+
def self.current
|
8
|
+
period_for_date(Date.today)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.period_for_date(date)
|
12
|
+
SubscriptionPeriod.where('start_date <= ?', date).order('start_date desc').limit(1).first
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|