Class: ShoppingCart::AddCoupon
- Inherits:
-
Rectify::Command
- Object
- Rectify::Command
- ShoppingCart::AddCoupon
- Defined in:
- app/services/shopping_cart/add_coupon.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(code:, order:) ⇒ AddCoupon
constructor
A new instance of AddCoupon.
Constructor Details
#initialize(code:, order:) ⇒ AddCoupon
Returns a new instance of AddCoupon.
3 4 5 6 |
# File 'app/services/shopping_cart/add_coupon.rb', line 3 def initialize(code:, order:) @code = code @order = order end |
Instance Method Details
#call ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/services/shopping_cart/add_coupon.rb', line 8 def call coupon = Coupon.find_by_code(@code) return broadcast(:invalid) unless coupon @order.update(coupon: coupon) broadcast(:ok) end |