Class: SolidusGraphqlApi::Mutations::Checkout::SelectShippingRate

Inherits:
BaseMutation
  • Object
show all
Defined in:
lib/solidus_graphql_api/mutations/checkout/select_shipping_rate.rb

Instance Method Summary collapse

Instance Method Details

#ready?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/solidus_graphql_api/mutations/checkout/select_shipping_rate.rb', line 34

def ready?(*)
  current_ability.authorize!(:update, current_order, guest_token)
end

#resolve(shipping_rate:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/solidus_graphql_api/mutations/checkout/select_shipping_rate.rb', line 14

def resolve(shipping_rate:)
  current_order.update(state: :delivery)

  update_params = {
    shipments_attributes: {
      id: shipping_rate.shipment_id,
      selected_shipping_rate_id: shipping_rate.id
    }
  }

  if Spree::OrderUpdateAttributes.new(current_order, update_params).apply
    current_order.recalculate
    errors = []
  else
    errors = current_order.errors
  end

  { errors: user_errors('order', errors), order: current_order }
end