wp-graphql / wp-graphql-woocommerce

Add WooCommerce support and functionality to your WPGraphQL server
https://woographql.com
GNU General Public License v3.0
639 stars 129 forks source link

Shipping metrod [checkout mutation] #334

Closed felipepxavier closed 2 years ago

felipepxavier commented 4 years ago

Hello, I would like to know how to apply the value of the "shipping metrod", it seems to me to receive only one String, how to insert a value together in the mutation checkout? thankss

'shippingMethod' => array (
'type' => 'String',
'description' => __ ('Order shipping method', 'wp-graphql-woocommerce'),
kidunot89 commented 4 years ago

@felipepxavier See this :point_right: https://github.com/wp-graphql/wp-graphql-woocommerce/pull/182

felipepxavier commented 4 years ago

Hi, @kidunot89 , any suggestion?

using mutation: mutation ($input: UpdateShippingMethodInput!) { updateShippingMethod(input: $input) { clientMutationId cart { availableShippingMethods { packageDetails supportsShippingCalculator rates { id cost label } } chosenShippingMethod } } }

result:

message: Field "cart" is not defined by type UpdateShippingMethodInput."

{ "input":{ "clientMutationId": "dfgdfd", "cart": { "availableShippingMethods":{ "rates":{ "id": "66", "cost": "25.75", "label": "Method Test" } }, "chosenShippingMethod": "66" } } }

kidunot89 commented 4 years ago

@felipepxavier I'm sorry the example in the PR summary had an error and I've fixed it. Please try the updated mutation.

To clarify what changed the cart should be customer.

Also make sure you're using WooCommerce Session tokens. Read more about that [here] (https://github.com/wp-graphql/wp-graphql-woocommerce/pull/88)

felipepxavier commented 4 years ago

@kidunot89 hello! thanks for the feedback!

But in the documentation the mutation "UpdateShippingMethodPayload" accepts:

cart: Cart
clientMutationId: String!

However using "cart", it presents this message: "Field 'cart' is not defined by type UpdateShippingMethodInput. "

And replacing cart for customer shows this message: "Cannot query field 'customer' on type UpdateShippingMethodPayload "..

kidunot89 commented 4 years ago

@felipepxavier your input is incorrect. Look up the UpdateShippingMethodInput type in the docs. You should only have to pass the rateId to set the shipping method.

felipepxavier commented 4 years ago

@kidunot89 so i'm using the wrong mutation, i wanted to create a "shipping method" and apply it to the request, because i have an API that returns me several shipping method, so i wanted to link only the method that the user selects ..

felipepxavier commented 4 years ago

@kidunot89 confirm me one thing, we were unable to create shipping methods, but "select" the existing woocomerce native methods and "link" them in orders, this?

kidunot89 commented 4 years ago

Yea, if you wish to create a shipping method, you have to do it through WooCommerce admin or code. WooGraphQL doesn't provide that capability, but you can use any shipping method made available through WooCommerce Shipping Method API

felipepxavier commented 4 years ago

@kidunot89 I understand, but how does the shipping method identify the zip code to show shipping options? Is there a "query" that receives a zip code to consult?

felipepxavier commented 4 years ago

query GetShippingMethods { shippingMethods {

nodes {
  title
  methodId
  id
  description
}

} }

@kidunot89 this query shows the options, but I still haven't figured out how to view the value of each option in this list, or if it's possible.

kidunot89 commented 3 years ago

@felipepxavier Use the Documentation Explorer in the GraphQL IDE to look up the updateCustomer() mutation. The availableShippingMethods field uses the zip code set in the session customer's shipping address. You have to be using the session token for it to work.

kidunot89 commented 3 years ago

@felipepxavier Any updates on this?

felipepxavier commented 3 years ago

Hi, @kidunot89 ! I had to interrupt this project, so when I return I will give feedback here .. thanks!

kidunot89 commented 2 years ago

@felipepxavier Were you able to get the mutation working?