Sha256: 14fb5aa91fd15560f5dbe72fa008be2101a17ab09f12336bacfa91e1d4ebacf6

Contents?: true

Size: 886 Bytes

Versions: 49

Compression:

Stored size: 886 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.apply_automatically && promotion.codes.any?
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
solidus_core-3.2.9 app/models/spree/order_promotion.rb
solidus_core-3.2.8 app/models/spree/order_promotion.rb
solidus_core-3.2.7 app/models/spree/order_promotion.rb
solidus_core-3.2.6 app/models/spree/order_promotion.rb
solidus_core-3.1.9 app/models/spree/order_promotion.rb
solidus_core-3.2.5 app/models/spree/order_promotion.rb
solidus_core-3.2.4 app/models/spree/order_promotion.rb
solidus_core-3.2.3 app/models/spree/order_promotion.rb
solidus_core-3.1.8 app/models/spree/order_promotion.rb
solidus_core-3.0.8 app/models/spree/order_promotion.rb
solidus_core-3.2.2 app/models/spree/order_promotion.rb
solidus_core-3.2.1 app/models/spree/order_promotion.rb
solidus_core-3.2.0 app/models/spree/order_promotion.rb
solidus_core-3.2.0.alpha app/models/spree/order_promotion.rb
solidus_core-3.0.7 app/models/spree/order_promotion.rb
solidus_core-2.11.17 app/models/spree/order_promotion.rb
solidus_core-3.1.7 app/models/spree/order_promotion.rb
solidus_core-2.11.16 app/models/spree/order_promotion.rb
solidus_core-3.0.6 app/models/spree/order_promotion.rb
solidus_core-3.1.6 app/models/spree/order_promotion.rb