3 回答

TA貢獻1866條經驗 獲得超5個贊
現在可以了。如果您以前從未使用過 GraphQL 查詢,那么理解它們是一個挑戰。
以下是更多信息:
https://www.shopify.com/partners/blog/multi-location_and_graphql
$locationId = "gid://shopify/Location/1";
$inventoryItemAdjustments1['locationId'] = $locationId;
$inventoryItemAdjustments1['inventoryItemAdjustments']['inventoryItemId'] = 'gid://shopify/InventoryItem/1';
$inventoryItemAdjustments1['inventoryItemAdjustments']['availableDelta'] = 500;
$result = $api->graph('mutation inventoryBulkAdjustQuantityAtLocation($inventoryItemAdjustments: [InventoryAdjustItemInput!]!, $locationId: ID!)
{inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $inventoryItemAdjustments, locationId: $locationId) {userErrors { field message }}}',
$inventoryItemAdjustments1
);

TA貢獻1852條經驗 獲得超7個贊
不太好的例子(硬編碼值,別名 - 不是現實生活中的例子)......應該使用 graphql 變量,它們應該匹配突變要求('root'參數),在這種情況下和(對象數組locationId)inventoryItemAdjustments。
您可以使用如下定義的“查詢變量”在 graphiql/playground 中測試此突變:
{
locationId: "gid://shopify/Location/1",
inventoryItemAdjustments: [
{
'inventoryItemId': 'gid://shopify/InventoryItem/1',
'availableDelta': 500
},
{
'inventoryItemId': 'gid://shopify/InventoryItem/2',
'availableDelta': 100
}
]
}
...所以使用 php(關聯數組被編碼為 json 作為對象 - 為了可讀性而明確聲明)它應該看起來更像這樣:
$locationId = "gid://shopify/Location/1";
$inventoryItemAdjustments = [];
$inventoryItemAdjustments[] = (object)[
'inventoryItemId' => 'gid://shopify/InventoryItem/1',
'availableDelta'] => 500;
];
$inventoryItemAdjustments[] = (object)[
'inventoryItemId' => 'gid://shopify/InventoryItem/2',
'availableDelta'] => 100;
];
$variables = (object)[
'locationId' => $locationId;
'inventoryItemAdjustments' => $inventoryItemAdjustments
];
$result = $api->graph('mutation inventoryBulkAdjustQuantityAtLocation($inventoryItemAdjustments: [InventoryAdjustItemInput!]!, $locationId: ID!)
{inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $inventoryItemAdjustments, locationId: $locationId) {userErrors { field message }}}',
$variables
);

TA貢獻1825條經驗 獲得超4個贊
我想展示另一個使用它的庫并擴展最后一個例子。
我為 graphql 使用了一個稍微不同的庫: https://github.com/Shopify/shopify-php-api/
像這里發布的那樣更新庫存顯示 [statusCode:GuzzleHttp\Psr7\Response:private] => 200 所以它似乎有效但沒有反映在更新的庫存中。:(
檢查 /admin/products/inventory?location_id=62241177806&query=F11_27781195 不會顯示新庫存。我正確使用了 inventoryid(不是產品或 variantid)。
$inventoryItemAdjustments = array();
$inventoryItemAdjustments[] = (object)[
'inventoryItemId' => 'gid://shopify/InventoryItem/43151435235534',
'availableDelta' => 500
];
$inventoryItemAdjustments[] = (object)[
'inventoryItemId' => 'gid://shopify/InventoryItem/43151435268302',
'availableDelta' => 500
];
$variables = array(
'locationId' => ConfigClass::$locationId,
'inventoryItemAdjustments' => $inventoryItemAdjustments
);
$graphqlquery='mutation inventoryBulkAdjustQuantityAtLocation($inventoryItemAdjustments: [InventoryAdjustItemInput!]!, $locationId: ID!)
{inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $inventoryItemAdjustments, locationId: $locationId) {userErrors { field message }}}';
$response = $client->query(['query' => $graphqlquery, 'variables' => $variables]);
刪除產品有效(如果庫初始化良好,這是一個很好的測試):
$query = <<<QUERY
mutation {
productDelete(input: {id: "gid://shopify/Product/6975310463182"})
{
deletedProductId
}
}
QUERY;
$response = $client->query(["query" => $query]);
print_r($response);
die;
- 3 回答
- 0 關注
- 233 瀏覽
添加回答
舉報