Sha256: eb6aca0e33dac86e46acb6f59c24e38eabdc0f4784130031d869787b9bc20001

Contents?: true

Size: 804 Bytes

Versions: 42

Compression:

Stored size: 804 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'
    belongs_to :promotion, class_name: 'Spree::Promotion'
    belongs_to :promotion_code, class_name: 'Spree::PromotionCode'

    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

42 entries across 42 versions & 2 rubygems

Version Path
solidus_core-2.9.6 app/models/spree/order_promotion.rb
solidus_core-2.8.6 app/models/spree/order_promotion.rb
solidus_core-2.9.5 app/models/spree/order_promotion.rb
solidus_core-2.9.4 app/models/spree/order_promotion.rb
solidus_core-2.6.6 app/models/spree/order_promotion.rb
solidus_core-2.7.4 app/models/spree/order_promotion.rb
solidus_core-2.8.5 app/models/spree/order_promotion.rb
solidus_core-2.9.3 app/models/spree/order_promotion.rb
solidus_core-2.9.2 app/models/spree/order_promotion.rb
solidus_core-2.7.3 app/models/spree/order_promotion.rb
solidus_core-2.6.5 app/models/spree/order_promotion.rb
solidus_core-2.9.1 app/models/spree/order_promotion.rb
solidus_core-2.9.0 app/models/spree/order_promotion.rb
solidus_core-2.9.0.rc.1 app/models/spree/order_promotion.rb
solidus_core-2.8.4 app/models/spree/order_promotion.rb
solidus_core-2.8.3 app/models/spree/order_promotion.rb
solidus_core-2.7.2 app/models/spree/order_promotion.rb
solidus_core-2.6.4 app/models/spree/order_promotion.rb
solidus_core-2.8.2 app/models/spree/order_promotion.rb
solidus_core-2.8.1 app/models/spree/order_promotion.rb