Class: SolidusFriendlyPromotions::PromotionCode
- Inherits:
-
Spree::Base
- Object
- Spree::Base
- SolidusFriendlyPromotions::PromotionCode
- Defined in:
- app/models/solidus_friendly_promotions/promotion_code.rb,
app/models/solidus_friendly_promotions/promotion_code/batch_builder.rb
Defined Under Namespace
Classes: BatchBuilder
Instance Method Summary collapse
- #promotion_not_apply_automatically ⇒ Object
-
#usage_count(excluded_orders: []) ⇒ Integer
Number of times the code has been used overall.
- #usage_limit ⇒ Object
-
#usage_limit_exceeded?(excluded_orders: []) ⇒ Boolean
Whether the promotion code has exceeded its usage restrictions.
Instance Method Details
#promotion_not_apply_automatically ⇒ Object
47 48 49 |
# File 'app/models/solidus_friendly_promotions/promotion_code.rb', line 47 def promotion_not_apply_automatically errors.add(:base, :disallowed_with_apply_automatically) if promotion.apply_automatically end |
#usage_count(excluded_orders: []) ⇒ Integer
Number of times the code has been used overall
32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/solidus_friendly_promotions/promotion_code.rb', line 32 def usage_count(excluded_orders: []) promotion .discounted_orders .complete .where.not(spree_orders: {state: :canceled}) .joins(:friendly_order_promotions) .where(friendly_order_promotions: {promotion_code_id: id}) .where.not(id: excluded_orders.map(&:id)) .count end |
#usage_limit ⇒ Object
43 44 45 |
# File 'app/models/solidus_friendly_promotions/promotion_code.rb', line 43 def usage_limit promotion.per_code_usage_limit end |
#usage_limit_exceeded?(excluded_orders: []) ⇒ Boolean
Whether the promotion code has exceeded its usage restrictions
22 23 24 25 26 |
# File 'app/models/solidus_friendly_promotions/promotion_code.rb', line 22 def usage_limit_exceeded?(excluded_orders: []) return unless usage_limit usage_count(excluded_orders: excluded_orders) >= usage_limit end |