Sha256: b2ef9379844c633810bf1dde7815b764747e176ae472d4403e30c0a92a08e216

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

# The LineItem class is responsible for associating Line items to subscriptions.  # It tracks the following values:
#
# [Spree::LineItem] :spree_line_item The spree object which created this instance
#
# [SolidusSubscription::Subscription] :subscription The object responsible for
#   grouping all information needed to create new subscription orders together
#
# [Integer] :subscribable_id The id of the object to be added to new subscription
#   orders when they are placed
#
# [Integer] :quantity How many units of the subscribable should be included in
#   future orders
#
# [Integer] :interval How often subscription orders should be placed
#
# [Integer] :installments How many subscription orders should be placed
module SolidusSubscriptions
  class LineItem < ApplicationRecord
    include Interval

    belongs_to(
      :spree_line_item,
      class_name: '::Spree::LineItem',
      inverse_of: :subscription_line_items,
      optional: true,
    )
    has_one :order, through: :spree_line_item, class_name: '::Spree::Order'
    belongs_to(
      :subscription,
      class_name: 'SolidusSubscriptions::Subscription',
      inverse_of: :line_items,
      optional: true
    )
    belongs_to :subscribable, class_name: "::#{SolidusSubscriptions.configuration.subscribable_class}"

    validates :subscribable_id, presence: true
    validates :quantity, numericality: { greater_than: 0 }
    validates :interval_length, numericality: { greater_than: 0 }, unless: -> { subscription }
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_subscriptions-2.0.2 app/models/solidus_subscriptions/line_item.rb
solidus_subscriptions-2.0.1 app/models/solidus_subscriptions/line_item.rb
solidus_subscriptions-2.0.0 app/models/solidus_subscriptions/line_item.rb
solidus_subscriptions-1.1.0 app/models/solidus_subscriptions/line_item.rb
solidus_subscriptions-1.0.1 app/models/solidus_subscriptions/line_item.rb
solidus_subscriptions-1.0.0 app/models/solidus_subscriptions/line_item.rb
solidus_subscriptions-1.0.0.rc1 app/models/solidus_subscriptions/line_item.rb