Class: Spree::PromotionHandler::Coupon
- Inherits:
-
Object
- Object
- Spree::PromotionHandler::Coupon
- Defined in:
- app/models/spree/promotion_handler/coupon.rb
Instance Attribute Summary collapse
-
#coupon_code ⇒ Object
readonly
Returns the value of attribute coupon_code.
-
#error ⇒ Object
Returns the value of attribute error.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(order) ⇒ Coupon
constructor
A new instance of Coupon.
- #promotion ⇒ Object
- #set_error_code(c) ⇒ Object
- #set_success_code(c) ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(order) ⇒ Coupon
Returns a new instance of Coupon.
7 8 9 10 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 7 def initialize(order) @order = order @coupon_code = order.coupon_code && order.coupon_code.downcase end |
Instance Attribute Details
#coupon_code ⇒ Object (readonly)
Returns the value of attribute coupon_code.
4 5 6 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 4 def coupon_code @coupon_code end |
#error ⇒ Object
Returns the value of attribute error.
5 6 7 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 5 def error @error end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 4 def order @order end |
#status_code ⇒ Object
Returns the value of attribute status_code.
5 6 7 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 5 def status_code @status_code end |
#success ⇒ Object
Returns the value of attribute success.
5 6 7 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 5 def success @success end |
Instance Method Details
#apply ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 12 def apply if coupon_code.present? if promotion.present? && promotion.actions.exists? handle_present_promotion(promotion) elsif promotion_code && promotion_code.promotion.inactive? set_error_code :coupon_code_expired else set_error_code :coupon_code_not_found end end self end |
#promotion ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 36 def promotion @promotion ||= begin if promotion_code && promotion_code.promotion.active? promotion_code.promotion end end end |
#set_error_code(c) ⇒ Object
31 32 33 34 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 31 def set_error_code(c) @status_code = c @error = I18n.t(c, scope: 'spree') end |
#set_success_code(c) ⇒ Object
26 27 28 29 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 26 def set_success_code(c) @status_code = c @success = I18n.t(c, scope: 'spree') end |
#successful? ⇒ Boolean
44 45 46 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 44 def successful? success.present? && error.blank? end |