通过API在Shopify创建订单并分配至指定Location的实现方法咨询
Shopify 订单创建阶段直接指定门店Location的解决方案
一、GraphQL 原生订单创建方案
直接调用orderCreate突变创建正式订单,在订单项参数中指定fulfillmentLocationId,即可实现订单生成时直接绑定目标Location,不会触发系统默认Location分配规则,从根源避免中间错误数据产生。
突变示例
mutation orderCreate($input: OrderInput!) { orderCreate(input: $input) { order { id name fulfillments { location { id name } } } userErrors { field message } } }
入参示例
{ "input": { "lineItems": [ { "variantId": "gid://shopify/ProductVariant/[商品变体ID]", "quantity": 1, "fulfillmentLocationId": "gid://shopify/Location/[目标门店Location ID]" } ], "customerId": "gid://shopify/Customer/[对应客户ID]", "shippingAddress": { "address1": "收货地址1", "city": "城市", "province": "省份", "zip": "邮编", "countryCode": "国家编码" } // 其余订单所需参数按需补充 } }
注意:需提前确认目标Location有对应商品的可用库存,否则会触发库存不足报错
二、REST API 原生订单创建方案
调用订单创建接口POST /admin/api/[API版本]/orders.json时,在line_items参数中传入fulfillment_location_id字段即可绑定目标Location。
请求体示例
{ "order": { "line_items": [ { "variant_id": [商品变体数字ID], "quantity": 1, "fulfillment_location_id": [目标门店Location数字ID] } ], "customer": { "id": [对应客户数字ID] }, "shipping_address": { "address1": "收货地址1", "city": "城市", "province": "省份", "zip": "邮编", "country": "国家" } // 其余订单所需参数按需补充 } }
三、草稿订单流程兼容方案
若现有业务逻辑必须使用草稿订单中转,无需调整原有流程框架,只需在调用draftOrderCreate突变创建草稿订单时,给每个lineItem新增appliedFulfillmentLocationId参数传入目标Location ID,后续调用draftOrderComplete生成的正式订单会直接绑定指定Location,无需后续执行转移操作。
内容的提问来源于stack exchange,提问作者Peter S
相关产品推荐
相关产品推荐

