Class: SolidusGraphqlApi::Mutations::Checkout::UpdateCartQuantity

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

Instance Method Summary collapse

Instance Method Details

#authorized?(line_item:) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/solidus_graphql_api/mutations/checkout/update_cart_quantity.rb', line 31

def authorized?(line_item:, **)
  current_order.line_items.find(line_item.id)
end

#ready?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/solidus_graphql_api/mutations/checkout/update_cart_quantity.rb', line 35

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

#resolve(line_item:, quantity:) ⇒ Object



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

def resolve(line_item:, quantity:)
  update_params = {
    line_items_attributes: {
      id: line_item.id,
      quantity: quantity
    }
  }

  current_order.contents.update_cart(update_params)

  {
    order: current_order,
    errors: user_errors("line_item", line_item.errors)
  }
end