Class: Spree::PromotionCode

Inherits:
Base
  • Object
show all
Defined in:
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

Methods included from Spree::Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

- (Integer) usage_count

Number of times the code has been used overall

Returns:

  • (Integer)

    usage count



25
26
27
28
29
30
31
# File 'app/models/spree/promotion_code.rb', line 25

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

- (Object) usage_limit



33
34
35
# File 'app/models/spree/promotion_code.rb', line 33

def usage_limit
  promotion.per_code_usage_limit
end

- (Boolean) usage_limit_exceeded?

Whether the promotion code has exceeded its usage restrictions

Returns:

  • (Boolean)

    true or false



16
17
18
19
20
# File 'app/models/spree/promotion_code.rb', line 16

def usage_limit_exceeded?
  if usage_limit
    usage_count >= usage_limit
  end
end