Sha256: d076cab201cd775e9aec1875c8b0e03b540569a58aacfc56abec48b76bffad40

Contents?: true

Size: 852 Bytes

Versions: 6

Compression:

Stored size: 852 Bytes

Contents

# frozen_string_literal: true

module Spree
  # Spree::OrderPromotion represents the relationship between:
  #
  # 1. A promotion that a user attempted to apply to their order
  # 2. The specific code that they used
  class OrderPromotion < Spree::Base
    self.table_name = 'spree_orders_promotions'

    belongs_to :order, class_name: 'Spree::Order', optional: true
    belongs_to :promotion, class_name: 'Spree::Promotion', optional: true
    belongs_to :promotion_code, class_name: 'Spree::PromotionCode', optional: true

    validates :order, presence: true
    validates :promotion, presence: true
    validates :promotion_code, presence: true, if: :require_promotion_code?

    self.whitelisted_ransackable_associations = %w[promotion_code]

    private

    def require_promotion_code?
      promotion && promotion.codes.any?
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
solidus_core-2.10.5 app/models/spree/order_promotion.rb
solidus_core-2.10.3 app/models/spree/order_promotion.rb
solidus_core-2.10.2 app/models/spree/order_promotion.rb
solidus_core-2.10.1 app/models/spree/order_promotion.rb
solidus_core-2.10.0 app/models/spree/order_promotion.rb
solidus_core-2.10.0.beta1 app/models/spree/order_promotion.rb