Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Shopify Order Edit: XXX was not added because it's already on the order

Solved

Shopify Order Edit: XXX was not added because it's already on the order

Villiamjit
Shopify Partner
19 0 1

Hi Team,

 

I'm trying to create a new product variant with GraphQL API in the existing order.

 

here is the json code that I am using

 

{"query":"mutation orderEditAddVariant($id: ID!, $quantity: Int!, $variantId: ID!) {\r\n\t\t\t\t\torderEditAddVariant(id: $id, quantity: $quantity, variantId: $variantId) {\r\n\t\t\t\t\t\tcalculatedOrder {\r\n\t\t\t\t\t\t\tid\r\n\t\t\t\t\t\t\taddedLineItems(first:5) {\r\n\t\t\t\t\t\t\t edges {\r\n\t\t\t\t\t\t\t\t node {\r\n\t\t\t\t\t\t\t\t id\r\n\t\t\t\t\t\t\t\t quantity\r\n\t\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlineItems(first:10){\r\n\t\t\t\t\t\t\t\tedges {\r\n\t\t\t\t\t\t\t\t\tnode {\r\n\t\t\t\t\t\t\t\t\t id\r\n\t\t\t\t\t\t\t\t\t quantity\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcalculatedLineItem {\r\n\t\t\t\t\t\t\tid\r\n\t\t\t\t\t\t\ttitle\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t userErrors {\r\n\t\t\t\t\t\tfield\r\n\t\t\t\t\t\tmessage\r\n\t\t\t\t\t }\r\n\t\t\t\t\t}\r\n\t\t\t\t}","variables":{"allowDuplicates":true,"id":"gid:\/\/shopify\/CalculatedOrder\/28891938905","quantity":1,"variantId":"gid:\/\/shopify\/ProductVariant\/12408611176537"}}

But I am getting an error that this item is not able to add it's already added. But as you see I added "allowDuplicates":true, in my query that is used to allow duplicate products with order edit.

{"data":{"orderEditAddVariant":{"calculatedOrder":null,"calculatedLineItem":null,"userErrors":[{"field":["id"],"message":"All things American Black Tank Top - Black \/ S was not added because it's already on the order."}]}},"extensions":{"cost":{"requestedQueryCost":29,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":10000.0,"currentlyAvailable":9990,"restoreRate":500.0}}}}

 

Can anyone help me with this issue? as its really urgent for me to fix this.

 

Thanks,
Villiam

Screenshot_3.png

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 238 531

This is an accepted solution.

Hi @Villiamjit,

 

Thanks for your post. When using the orderEditAddVariant mutation in a test store with v2023-01 it's working as expected, returning that same error if the variant is already on the order unless allowDuplicates is set to true in which case it adds the item.

 

One thing that seems unusual about the example you provided is that in the return value calculatedOrder shows as null instead of showing some info about the calculatedOrder which could be a clue. As it is we have not been able to replicate that same problem with the information at hand.

 

Here's the query that was tested and which worked, perhaps trying this alternative formatting will help to track down what's going wrong:

 

mutation addVariantToOrder {
orderEditAddVariant(
 id: "gid://shopify/CalculatedOrder/47100000123"
 variantId: "gid://shopify/ProductVariant/3130000005456"
 quantity: 1
 allowDuplicates: true
) {
 calculatedOrder {
  id
  addedLineItems(first: 5) {
   edges {
    node {
     id
     quantity
    }
   }
  }
 }
 userErrors {
  field
  message
 }
}
}
 

If you're still having trouble after the above an option is to reach out to API support by choosing the Support option in the Partner dash, choosing the API option, and providing more specific details to enable a closer look at the environment.

 

Have a great day,
Jon551

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 7 (7)

ShopifyDevSup
Shopify Staff
1453 238 531

This is an accepted solution.

Hi @Villiamjit,

 

Thanks for your post. When using the orderEditAddVariant mutation in a test store with v2023-01 it's working as expected, returning that same error if the variant is already on the order unless allowDuplicates is set to true in which case it adds the item.

 

One thing that seems unusual about the example you provided is that in the return value calculatedOrder shows as null instead of showing some info about the calculatedOrder which could be a clue. As it is we have not been able to replicate that same problem with the information at hand.

 

Here's the query that was tested and which worked, perhaps trying this alternative formatting will help to track down what's going wrong:

 

mutation addVariantToOrder {
orderEditAddVariant(
 id: "gid://shopify/CalculatedOrder/47100000123"
 variantId: "gid://shopify/ProductVariant/3130000005456"
 quantity: 1
 allowDuplicates: true
) {
 calculatedOrder {
  id
  addedLineItems(first: 5) {
   edges {
    node {
     id
     quantity
    }
   }
  }
 }
 userErrors {
  field
  message
 }
}
}
 

If you're still having trouble after the above an option is to reach out to API support by choosing the Support option in the Partner dash, choosing the API option, and providing more specific details to enable a closer look at the environment.

 

Have a great day,
Jon551

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

benbenben1
Shopify Partner
5 0 0

I do not believe this is accurate. I am getting the same error even when I have allowDuplicates set to true.

ShopifyDevSup
Shopify Staff
1453 238 531

Hi @benbenben1 

 

I've ran that query again, adding a duplicate variant to an existing order with the same query that Jon shared above, and I can confirm that we are still unable to replicate the error. I was successfully able to add a duplicate line item with the orderEditAddVariant mutation, with allowDuplicates: true.

Since we are unable to replicate the error on our end, and the mutation is working as expected, we will need further context from you to be able to help look into the error you are receiving, with specific examples of api calls that have failed.

If you can please prepare answers to the following troubleshooting questions, and reach out to our Partner Support team via your Partner Dashboard and provide Partner Support with your answers to the questions below. Once you've reached out through the Support team we can help look into the error occurring with your app specifically in further detail. This is required so that we can authenticate with the store and app where the error is occurring and look into this further within in our internal logs if needed.

 

Troubleshooting questions needed to look into this further, Please fill this out with as much detail as possible:

1. Expected Behavior vs. Actual Behavior

  • In general store terms what is the API action trying to do?
  • What is the expected result?
  • What is happening instead?

2. Environment & Scope of the Issue

  • What is the name of the App making the API call? (URL of app in store admin is best if possible)
  • Is the issue happening for multiple stores or just one? Please include one or more specific store URL's.
  • What version of the API is being used? eg. 2023-10 [Shopify API Versioning]
  • What is the scope of the issue? eg. Is it happening only via the API or is there an aspect that affects the admin or storefront as well?

3. Timeframe

  • When did this happen? A log search requires a specific date, time, and timezone within the last 7 days when the issue occurred.
  • Has something that has been working for a while suddenly stopped working? If so, when was the last successful attempt?
  • About how many times did the issue occur? Does it happen every time or only occasionally?

4. New Feature or Existing

  • Is this something you are currently building or has it been around a while?
  • Has it ever worked? If it has never worked, what makes you think it should?
  • What specific part of the official API docs are being followed? [Shopify API Docs]

5. Replication and Raw Example

  • What is the exact API call being made (including the Request URL, body, and headers where applicable)?
  • Can the issue be replicated?
    • If so, what steps need to be taken to replicate the issue?
    • If not, please tell us more about why.
  • Please provide both the full HTTP request and response including x-request-id if possible [Raw Request Example] (no access tokens or passwords please)
  • Is the issue happening with a specific resource like Order or Product?
    • Please include a link to the resource in the admin, or an ID that we can use to identify the affected resource.

 

We appreciate your understanding in that we do require ALL of the information above to fully troubleshoot and determine any issues that may be occurring when using our API.

I hope this helps, and I hope you have a great day 🙂

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

benbenben1
Shopify Partner
5 0 0

If you create a calculated order with "orderEditBegin" mutation then add a variant to that calculated order using the "orderEditAddVariant" (with allowDuplicates:true) -- I can even add the same variant twice with orderEditAddVariant, then commit that order edit with "orderEditCommit" mutation that all succeeds. So it seems like allowDuplicates is working as expected here.

The issue is introduced if I take the original order again and repeat the exact same steps. Create a new 2nd calculatedOrder with the orderEditBegin mutation and then try to add that same variant again... now I get an error saying it's already on the order.

 

Here's a screenshot of the exact request and response where you can see the issue even though allowDuplicates is true.

Pasted_Image_6_20_24__4_12_PM.jpg

benbenben1
Shopify Partner
5 0 0

I think the Shopify docs should be updated to make it clearer that you are NOT able to use orderEditAddVariant to add a variant to an order if that variant is already on the original order. allowDuplicates allows you to add duplicates on the calculated order but not on the original order.

FullerEcommerce
Shopify Partner
1 0 1

Hi @ben ,

 

There is an error in your graphQL mutation.  You haven't used the variable for allowDuplicates in your mutation you have only defined in your variables so the mutation runs with the default false flag.  The mutation needs to be updated as per below:

mutation orderEditAddVariant($id: !ID, $quantity: Int!, $variantID: ID!, $allowDuplicates: Boolean){

    orderEditAddVariant(id: $id, quantity: $quantity, variantId: $variantId, allowDuplicates: $allowDuplicates) {

 

You need the allowduplicates in both the mutation definition and mutation type.  Once there your variable will make its way into your mutation and correctly set the flag to True and allow you to add additional orderlines of the same variant.  

Thanks,
Max

 

benbenben1
Shopify Partner
5 0 0

You're right Max 😳 thank you for checking that