Class: Spree::PromotionHandler::Coupon
- Inherits:
-
Object
- Object
- Spree::PromotionHandler::Coupon
- Defined in:
- app/models/spree/promotion_handler/coupon.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#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
- #successful? ⇒ Boolean
Constructor Details
#initialize(order) ⇒ Coupon
Returns a new instance of Coupon.
7 8 9 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 7 def initialize(order) @order = order end |
Instance Attribute Details
#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 |
#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
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 11 def apply if order.coupon_code.present? if promotion.present? && promotion.actions.exists? handle_present_promotion(promotion) else if Promotion.with_coupon_code(order.coupon_code).try(:expired?) self.error = Spree.t(:coupon_code_expired) else self.error = Spree.t(:coupon_code_not_found) end end end self end |
#promotion ⇒ Object
27 28 29 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 27 def promotion @promotion ||= Promotion.active.includes(:promotion_rules, :promotion_actions).with_coupon_code(order.coupon_code) end |
#successful? ⇒ Boolean
31 32 33 |
# File 'app/models/spree/promotion_handler/coupon.rb', line 31 def successful? success.present? && error.blank? end |