Error using draftOrderCalculate mutation with cart transform

We noticed a weird behaviour in the GraphQL draftOrderCalculate mutation which might be a bug. This is the setup:

  • We have an app installed called FeeBee that uses a cart transform function to expand our products with a bottle deposit product
  • When calling the draftOrderCalculate mutation with a line item discount, we get an exception
  • If we disable FeeBee, everything works fine. So my guess is that the cart transform breaks the discount distribution
  • I have tested this with all available API versions

Mutation:

mutation ($input: DraftOrderInput!) {
  draftOrderCalculate(input: $input) {
    calculatedDraftOrder {
      availableShippingRates {
        handle
        price {
          amount
          currencyCode
        }
        title
      }
      lineItems {
        bundleComponents {
          title
        }
        variant {
          id
        }
        originalUnitPriceSet {
          presentmentMoney {
            amount
          }
        }
      }
      lineItemsSubtotalPrice {
        presentmentMoney {
          amount
        }
      }
      shippingLine {
        shippingRateHandle
        title
        taxLines {
          priceSet {
            presentmentMoney {
              amount
            }
          }
          rate
        }
      }
      taxesIncluded
      taxLines {
        priceSet {
          presentmentMoney {
            amount
          }
        }
        rate
      }
      totalPriceSet {
        presentmentMoney {
          amount
        }
      }
      totalShippingPriceSet {
        presentmentMoney {
          amount
        }
      }
      totalTaxSet {
        presentmentMoney {
          amount
        }
      }
    }
    userErrors {
      message
      field
    }
  }
}

Variables:

{
  "input": {
    "billingAddress": {
      "address1": "Musterstraße 123",
      "city": "Karlsruhe",
      "company": "",
      "countryCode": "DE",
      "firstName": "Max",
      "lastName": "Muster",
      "provinceCode": "",
      "zip": "76137"
    },
    "purchasingEntity": {
      "customerId": "gid://shopify/Customer/23033114198389"
    },
    "lineItems": [
      {
        "appliedDiscount": {
          "amountWithCurrency": {
            "amount": "7.85",
            "currencyCode": "EUR"
          },
          "value": 7.85,
          "valueType": "FIXED_AMOUNT"
        },
        "quantity": 2,
        "variantId": "gid://shopify/ProductVariant/46611957809404"
      }
    ],
    "shippingAddress": {
      "address1": "Musterstraße 123",
      "city": "Karlsruhe",
      "company": "",
      "countryCode": "DE",
      "firstName": "Max",
      "lastName": "Muster",
      "provinceCode": "",
      "zip": "76137"
    },
    "shippingLine": {
      "priceWithCurrency": null,
      "shippingRateHandle": "f353893d3d00300e39d1ec83f9956055",
      "title": null
    },
    "useCustomerDefaultAddress": false,
    "presentmentCurrencyCode": "EUR"
  }
}

Response:

{
  "data": {
    "draftOrderCalculate": {
      "calculatedDraftOrder": null,
      "userErrors": [
        {
          "message": "Applied discount value can have at most 2 digits after decimal point",
          "field": [
            "lineItems",
            "0",
            "appliedDiscount",
            "value"
          ]
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 17,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1990,
        "restoreRate": 100
      }
    }
  }
}

My Findings

  • The error only happens when the cart transform is enabled
  • The error only happens when there is a line item discount
  • The error only happens when the item quantity is > 1
  • The error does not occur when we increase the discount to 7.86. However, the error re-occurs when we increase the line item quantity to e.g. 7
  • My guess is that splitting the discount between the expanded sub-items is broken

Hi Tobias,

Thanks for flagging this - have connected with the cart transform team on this, and will update when I hear back from them!

1 Like

Hi again Tobias,

From looking into this, our product team believe that the cart transform function provided by FeeBee seems to be what is causing the problem here. From the error being returned by the mutation, some line is getting updated to a total money value with too many decimals, and given that disabling FeeBee gets ride of the error, it seems like the best option is to connect with them directly.

Hi Liam, thanks for following up on this one! I am actually one of the devs of FeeBee and we found this bug with one of our customers. I checked on the function logs. Here is what I did:

  • Run the GraphQL query as above, it did throw the exception as expected
  • Checked the logs of the function run

Here is the input the function received

{
  "localization": {
    "market": {
      "id": "gid://shopify/Market/17257464060"
    }
  },
  "cart": {
    "lines": [
      {
        "id": "gid://shopify/CartLine/ae5fdc78-a8e1-4fd9-9ea3-33b0c155dcd0",
        "quantity": 2,
        "cost": {
          "amountPerQuantity": {
            "amount": "49.9",
            "currencyCode": "EUR"
          }
        },
        "merchandise": {
          "__typename": "ProductVariant",
          "id": "gid://shopify/ProductVariant/46611957809404",
          "title": null,
          "feeSettings": {
            "value": "redacted"
          },
          "product": {
            "inCollections": []
          }
        },
        "attribute1": null,
        "attribute2": null,
        "attribute3": null
      }
    ]
  },
  "presentmentCurrencyRate": "1.0",
  "cartTransform": {
    "feeConfigurations": {
      "value": "redacted"
    }
  }
}

And this is the output we generated:

{
  "operations": [
    {
      "expand": {
        "cartLineId": "gid://shopify/CartLine/ae5fdc78-a8e1-4fd9-9ea3-33b0c155dcd0",
        "expandedCartItems": [
          {
            "merchandiseId": "gid://shopify/ProductVariant/46611957809404",
            "price": {
              "adjustment": {
                "fixedPricePerUnit": {
                  "amount": "49.9"
                }
              }
            },
            "quantity": 1
          },
          {
            "merchandiseId": "gid://shopify/ProductVariant/46609857216764",
            "price": {
              "adjustment": {
                "fixedPricePerUnit": {
                  "amount": "1.92"
                }
              }
            },
            "quantity": 1
          }
        ]
      }
    }
  ]
}

Things to note:

  • We only work on the non-discounted price (amountPerQuantity)
  • We use the price adjustment with only 2 decimal places

For me this looks correct. Please correct me if you see an issue with this run. One more thing: I tried to replicate (same product, same quantities, same discount, etc.) the draft order using the admin UI and everything works as expected without any errors being thrown, see the attached screenshot.

The input and output of our cart transform function is exactly the same as when calling the draftOrderCalculate mutation. I aware that the admin ui doesn’t directly call the same GraphQL API that we call, but probably if it works in the ui it should also work through the GraphQL Admin API?

Hi @Liam-Shopify, sorry for pinging you again. Can you share some info if you and the team are re-evaluating the issue considering my follow up info?

Hi Tobias - have reconnected with our internal team and will let you know what I hear back.

1 Like