Files
openfoodnetwork/app/models/subscription_line_item.rb
luisramos0 c66e5fe1e9 Make subscription line items handle soft deleted variants
This ensures subscription list page works. The variant can be removed from the subscription by the user in the edit subscription page
2019-09-22 14:59:59 +01:00

28 lines
734 B
Ruby

class SubscriptionLineItem < ActiveRecord::Base
belongs_to :subscription, inverse_of: :subscription_line_items
belongs_to :variant, class_name: 'Spree::Variant'
validates :subscription, presence: true
validates :variant, presence: true
validates :quantity, presence: true, numericality: { only_integer: true }
def total_estimate
(price_estimate || 0) * (quantity || 0)
end
# Ensure SubscriptionLineItem always has access to soft-deleted Variant attribute
def variant
Spree::Variant.unscoped { super }
end
# Used to calculators to estimate fees
alias_method :amount, :total_estimate
# Used to calculators to estimate fees
def price
price_estimate
end
default_scope order('id ASC')
end