Sha256: 777ca50f1c365a2c3ea60110bc788d4cab02ac65e6e69e5a3f3e0a8dda2cd58e
Contents?: true
Size: 950 Bytes
Versions: 6
Compression:
Stored size: 950 Bytes
Contents
class Spree::PromotionCode < Spree::Base belongs_to :promotion, inverse_of: :codes belongs_to :promotion_code_batch, class_name: "Spree::PromotionCodeBatch" has_many :adjustments validates :value, presence: true, uniqueness: { allow_blank: true } validates :promotion, presence: true before_save :normalize_code self.whitelisted_ransackable_attributes = ['value'] # Whether the promotion code has exceeded its usage restrictions # # @return true or false def usage_limit_exceeded? if usage_limit usage_count >= usage_limit end end # Number of times the code has been used overall # # @return [Integer] usage count def usage_count adjustments.eligible. joins(:order). merge(Spree::Order.complete). distinct. count(:order_id) end def usage_limit promotion.per_code_usage_limit end private def normalize_code self.value = value.downcase.strip end end
Version data entries
6 entries across 6 versions & 1 rubygems