Class: Spree::PromotionCode

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

Defined Under Namespace

Classes: CodeBuilder

Instance Method Summary collapse

Instance Method Details

#usage_countInteger

Number of times the code has been used overall

Returns:

  • (Integer)

    usage count



22
23
24
25
26
27
28
# File 'app/models/spree/promotion_code.rb', line 22

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

#usage_limitObject



30
31
32
# File 'app/models/spree/promotion_code.rb', line 30

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



13
14
15
16
17
# File 'app/models/spree/promotion_code.rb', line 13

def usage_limit_exceeded?
  if usage_limit
    usage_count >= usage_limit
  end
end