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

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 00:19:58