Sha256: be076fdc5d768f73dde882157cc730922e6faeb02a9a352779a8a42ed7cb1864

Contents?: true

Size: 794 Bytes

Versions: 5

Compression:

Stored size: 794 Bytes

Contents

# frozen_string_literal: true

module SolidusPromotions
  # SolidusPromotions::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
    belongs_to :order, class_name: "Spree::Order"
    belongs_to :promotion, -> { with_discarded }, class_name: "SolidusPromotions::Promotion"
    belongs_to :promotion_code, class_name: "SolidusPromotions::PromotionCode", optional: 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

5 entries across 5 versions & 1 rubygems

Version Path
solidus_promotions-4.5.1 app/models/solidus_promotions/order_promotion.rb
solidus_promotions-4.5.0 app/models/solidus_promotions/order_promotion.rb
solidus_promotions-4.4.2 app/models/solidus_promotions/order_promotion.rb
solidus_promotions-4.4.1 app/models/solidus_promotions/order_promotion.rb
solidus_promotions-4.4.0 app/models/solidus_promotions/order_promotion.rb