Class: Spree::Promo::CouponApplicator
- Inherits:
-
Object
- Object
- Spree::Promo::CouponApplicator
- Defined in:
- lib/spree/promo/coupon_applicator.rb
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
- #apply ⇒ Object
-
#initialize(order) ⇒ CouponApplicator
constructor
A new instance of CouponApplicator.
Constructor Details
#initialize(order) ⇒ CouponApplicator
Returns a new instance of CouponApplicator.
6 7 8 |
# File 'lib/spree/promo/coupon_applicator.rb', line 6 def initialize(order) @order = order end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'lib/spree/promo/coupon_applicator.rb', line 4 def order @order end |
Instance Method Details
#apply ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/spree/promo/coupon_applicator.rb', line 10 def apply if @order.coupon_code.present? # check if coupon code is already applied if @order.adjustments.promotion.eligible.detect { |p| p.originator.promotion.code == @order.coupon_code }.present? return { :coupon_applied? => true, :notice => Spree.t(:coupon_code_already_applied) } else promotion = Spree::Promotion.find_by_code(@order.coupon_code) if promotion.present? handle_present_promotion(promotion) else return { :coupon_applied? => false, :error => Spree.t(:coupon_code_not_found) } end end else return { :coupon_applied? => true } end end |