Module: Workarea::Pricing::Discount::Conditions::PromoCodes
- Extended by:
- ActiveSupport::Concern
- Included in:
- BuySomeGetSome, Workarea::Pricing::Discount::Category, FreeGift, OrderTotal, Product, ProductAttribute, QuantityFixedPrice, Shipping
- Defined in:
- app/models/workarea/pricing/discount/conditions/promo_codes.rb
Instance Method Summary collapse
-
#generated_codes ⇒ nil, CodeList
The generated codes this discount is configured to check as part of its conditions.
-
#promo_code? ⇒ Boolean
Whether this discount has any promo code conditions.
-
#promo_codes_qualify?(order) ⇒ Boolean
Whether this discount passes its promo code conditions.
- #valid? ⇒ Boolean
Instance Method Details
#generated_codes ⇒ nil, CodeList
The generated codes this discount is configured to check as part of its conditions.
35 36 37 |
# File 'app/models/workarea/pricing/discount/conditions/promo_codes.rb', line 35 def generated_codes @generated_codes ||= CodeList.find(generated_codes_id) rescue nil end |
#promo_code? ⇒ Boolean
Whether this discount has any promo code conditions.
43 44 45 |
# File 'app/models/workarea/pricing/discount/conditions/promo_codes.rb', line 43 def promo_code? promo_codes.present? || generated_codes_id.present? end |
#promo_codes_qualify?(order) ⇒ Boolean
Whether this discount passes its promo code conditions.
52 53 54 55 56 57 58 59 |
# File 'app/models/workarea/pricing/discount/conditions/promo_codes.rb', line 52 def promo_codes_qualify?(order) return true unless promo_code? codes = order.promo_codes.reject(&:blank?).map(&:downcase) return false if codes.empty? array_qualifies?(codes) || generated_qualifies?(codes) end |
#valid? ⇒ Boolean
25 26 27 28 |
# File 'app/models/workarea/pricing/discount/conditions/promo_codes.rb', line 25 def valid?(*) promo_codes.map!(&:downcase) super end |