You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:使用Shopify iOS SDK通过GraphQL查询订单状态

解决Shopify iOS SDK查询订单状态的问题

嘿,作为刚接触GraphQL和Shopify的新手,找不到订单状态的查询方式太正常了——其实它就藏在你已经在用的Order对象字段里,只是你没留意到而已!

你当前的查询已经能获取订单的基础信息,只需要在node的字段列表里添加status字段,就能拿到订单的核心状态了。修改后的GraphQL查询如下:

{
  customer(customerAccessToken: "token") {
    orders(first: 20) {
      edges {
        node {
          id
          orderNumber
          totalPrice
          currencyCode
          customerLocale
          customerUrl
          email
          phone
          processedAt
          subtotalPrice
          totalRefunded
          totalShippingPrice
          totalTax
          # 获取订单核心状态
          status
          shippingAddress {
            address1
            address2
            city
            company
            country
            countryCode
            firstName
            formatted
            formattedArea
            lastName
            latitude
            longitude
            name
            phone
            province
            provinceCode
            zip
          }
        }
      }
    }
  }
}

额外的状态细节(可选)

如果你需要更细分的状态信息,比如付款或发货状态,还可以加上这两个常用字段:

  • financialStatus:返回订单的付款状态,枚举值包括PAID、UNPAID、REFUNDED、PARTIALLY_REFUNDED等
  • fulfillmentStatus:返回订单的发货状态,枚举值包括FULFILLED、UNFULFILLED、PARTIALLY_FULFILLED等

添加后的查询示例:

{
  customer(customerAccessToken: "token") {
    orders(first: 20) {
      edges {
        node {
          # 原有字段...
          status
          financialStatus
          fulfillmentStatus
          # 地址信息...
        }
      }
    }
  }
}

在iOS SDK中使用

当你用Shopify iOS SDK处理查询结果时,对应的Storefront.Order模型会自动包含这些状态属性。比如你可以这样获取状态值:

if let order = orderNode {
    let orderStatus = order.status.rawValue // 比如 "OPEN"、"CLOSED"
    let paymentStatus = order.financialStatus?.rawValue // 比如 "PAID"
    let fulfillmentStatus = order.fulfillmentStatus?.rawValue // 比如 "FULFILLED"
}

这些枚举值都是Shopify官方定义的,完全适配SDK的解析逻辑,不用额外处理就能直接用啦!

内容的提问来源于stack exchange,提问作者Vipulk617

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:20:54