Sha256: 019d3cfcf4c595d3545d80b97ee905a45a6c4a5e6380ba0928a69c0da7316529

Contents?: true

Size: 882 Bytes

Versions: 36

Compression:

Stored size: 882 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.allowed_ransackable_associations = %w[promotion_code]

    private

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

Version data entries

36 entries across 36 versions & 2 rubygems

Version Path
solidus_legacy_promotions-4.4.2 app/models/spree/order_promotion.rb
solidus_legacy_promotions-4.4.1 app/models/spree/order_promotion.rb
solidus_legacy_promotions-4.4.0 app/models/spree/order_promotion.rb
solidus_core-4.3.4 app/models/spree/order_promotion.rb
solidus_core-4.2.4 app/models/spree/order_promotion.rb
solidus_core-4.1.5 app/models/spree/order_promotion.rb
solidus_core-4.3.3 app/models/spree/order_promotion.rb
solidus_core-4.3.2 app/models/spree/order_promotion.rb
solidus_core-4.1.4 app/models/spree/order_promotion.rb
solidus_core-4.3.1 app/models/spree/order_promotion.rb
solidus_core-4.3.0 app/models/spree/order_promotion.rb
solidus_core-4.2.3 app/models/spree/order_promotion.rb
solidus_core-4.1.3 app/models/spree/order_promotion.rb
solidus_core-4.0.4 app/models/spree/order_promotion.rb
solidus_core-3.4.6 app/models/spree/order_promotion.rb
solidus_core-4.0.3 app/models/spree/order_promotion.rb
solidus_core-4.1.2 app/models/spree/order_promotion.rb
solidus_core-4.2.2 app/models/spree/order_promotion.rb
solidus_core-3.4.5 app/models/spree/order_promotion.rb
solidus_core-4.2.1 app/models/spree/order_promotion.rb