Class: Spree::PromotionCode

Inherits:
Base
  • Object
show all
Defined in:
core/app/models/spree/promotion_code.rb

Defined Under Namespace

Classes: BatchBuilder

Instance Method Summary collapse

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Instance Method Details

#usage_countInteger

Number of times the code has been used overall

Returns:

  • (Integer)

    usage count



27
28
29
30
31
32
33
# File 'core/app/models/spree/promotion_code.rb', line 27

def usage_count
  adjustments.eligible.
    joins(:order).
    merge(Spree::Order.complete).
    distinct.
    count(:order_id)
end

#usage_limitObject



35
36
37
# File 'core/app/models/spree/promotion_code.rb', line 35

def usage_limit
  promotion.per_code_usage_limit
end

#usage_limit_exceeded?Boolean

Whether the promotion code has exceeded its usage restrictions

Returns:

  • (Boolean)

    true or false



18
19
20
21
22
# File 'core/app/models/spree/promotion_code.rb', line 18

def usage_limit_exceeded?
  if usage_limit
    usage_count >= usage_limit
  end
end