Class: SolidusGraphqlApi::Mutations::Checkout::ApplyCouponCode
- Inherits:
-
BaseMutation
- Object
- GraphQL::Schema::RelayClassicMutation
- BaseMutation
- SolidusGraphqlApi::Mutations::Checkout::ApplyCouponCode
- Defined in:
- lib/solidus_graphql_api/mutations/checkout/apply_coupon_code.rb
Instance Method Summary collapse
Instance Method Details
#ready? ⇒ Boolean
26 27 28 |
# File 'lib/solidus_graphql_api/mutations/checkout/apply_coupon_code.rb', line 26 def ready?(*) current_ability.(:update, current_order, guest_token) end |
#resolve(coupon_code:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/solidus_graphql_api/mutations/checkout/apply_coupon_code.rb', line 14 def resolve(coupon_code:) current_order.coupon_code = coupon_code handler = Spree::PromotionHandler::Coupon.new(current_order).apply current_order.errors.add(:coupon_code, handler.error) unless handler.successful? { order: current_order, errors: user_errors("order", current_order.errors) } end |