如何从shopify Graphql api获取订单列表?我甚至想不出怎么才能得到一份订单。我能说的最接近的情况是我的查询应该是这样的:
query{
node(id:$id){
__typename
... on Order{
id
email
}
}
}根据文档,$id是“具有支持全局标识的ID的对象”,但不清楚这是什么意思。对于产品,您可以像这样检索id:
shop {
productByHandle(handle: "red-bicycle") {
id
}
}然后它将返回一个散列,如下所示:
Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyODE0NzU=
然后,您可以使用节点接口查询产品,如下所示:
node(id: "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0Lzk4OTUyODE0NzU=") {
id
... on Product {
title
}
} 但是,对于订单,如何做到这一点呢?查看最近5个订单的列表?为什么一定要使用Node接口呢?为什么不使用句柄或ID等来查询,而使用散列呢?
发布于 2018-01-05 00:47:59
您可以使用此查询获取用户的订单列表
let query = Storefront.buildQuery { $0
.customer(customerAccessToken: token) { $0
.orders(first: 20) { $0
.edges { $0
.node { $0
.id()
.orderNumber()
.totalPrice()
.currencyCode()
.customerLocale()
.customerUrl()
.email()
.phone()
.processedAt()
.subtotalPrice()
.totalRefunded()
.totalShippingPrice()
.totalTax()
.shippingAddress( { $0
.address1()
.address2()
.city()
.company()
.country()
.countryCode()
.firstName()
.formatted()
.formattedArea()
.lastName()
.latitude()
.longitude()
.name()
.phone()
.province()
.provinceCode()
.zip()
})
.lineItems(first: 50) { $0
.edges { $0
.cursor()
.node { $0
.quantity()
.title()
.variant{ $0
.id()
.image({ $0
.altText()
.id()
.src()
})
.price()
.sku()
}
.customAttributes{ $0
.key()
.value()
}
}
}
}
}
}
}
}
}这个查询在iOS中返回用户的订单列表,希望它能为您工作。
https://stackoverflow.com/questions/47910822
复制相似问题