Shopify中创建产品后如何发布至在线商店及设置库存?
Shopify产品发布与库存设置解决方案
一、确定在线商店对应的Publication ID
由于name字段已弃用,可通过查询publications时获取type和status字段定位在线商店ID:
- 在线商店的
type固定为ONLINE_STORE,且状态为ACTIVE - 示例查询语句:
query GetPublications { publications(first: 10) { edges { node { id type status } } } }
返回结果中,筛选出type: ONLINE_STORE且status: ACTIVE的节点ID,即为在线商店的Publication ID。
二、设置新产品的库存数量
有两种方式可设置库存:
1. 创建产品时直接设置库存
在productCreate mutation中,给产品变体添加inventoryQuantity和inventoryManagement参数(需启用Shopify库存管理):
mutation CreateProductWithInventory { productCreate(input: { title: "新测试产品", variants: [ { price: "29.99", inventoryQuantity: 50, inventoryManagement: SHOPIFY } ] }) { product { id title } userErrors { message field } } }
2. 创建产品后单独更新库存
若已创建产品,可使用inventorySetQuantity mutation调整库存:
mutation SetInventoryQuantity { inventorySetQuantity( inventoryItemId: "gid://shopify/InventoryItem/123456789", locationId: "gid://shopify/Location/987654321", quantity: 30 ) { inventoryItem { id quantityOnHand } userErrors { message field } } }
注意:需先通过产品ID查询到对应的inventoryItemId和店铺的locationId。
内容的提问来源于stack exchange,提问作者Wakil Ahmed
相关产品推荐
相关产品推荐

