3 回答

TA貢獻(xiàn)1866條經(jīng)驗(yàn) 獲得超5個(gè)贊
現(xiàn)在可以了。如果您以前從未使用過(guò) GraphQL 查詢,那么理解它們是一個(gè)挑戰(zhàn)。
以下是更多信息:
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貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊
不太好的例子(硬編碼值,別名 - 不是現(xiàn)實(shí)生活中的例子)......應(yīng)該使用 graphql 變量,它們應(yīng)該匹配突變要求('root'參數(shù)),在這種情況下和(對(duì)象數(shù)組locationId)inventoryItemAdjustments。
您可以使用如下定義的“查詢變量”在 graphiql/playground 中測(cè)試此突變:
{
locationId: "gid://shopify/Location/1",
inventoryItemAdjustments: [
{
'inventoryItemId': 'gid://shopify/InventoryItem/1',
'availableDelta': 500
},
{
'inventoryItemId': 'gid://shopify/InventoryItem/2',
'availableDelta': 100
}
]
}
...所以使用 php(關(guān)聯(lián)數(shù)組被編碼為 json 作為對(duì)象 - 為了可讀性而明確聲明)它應(yīng)該看起來(lái)更像這樣:
$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貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
我想展示另一個(gè)使用它的庫(kù)并擴(kuò)展最后一個(gè)例子。
我為 graphql 使用了一個(gè)稍微不同的庫(kù): https://github.com/Shopify/shopify-php-api/
像這里發(fā)布的那樣更新庫(kù)存顯示 [statusCode:GuzzleHttp\Psr7\Response:private] => 200 所以它似乎有效但沒(méi)有反映在更新的庫(kù)存中。:(
檢查 /admin/products/inventory?location_id=62241177806&query=F11_27781195 不會(huì)顯示新庫(kù)存。我正確使用了 inventoryid(不是產(chǎn)品或 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]);
刪除產(chǎn)品有效(如果庫(kù)初始化良好,這是一個(gè)很好的測(cè)試):
$query = <<<QUERY
mutation {
productDelete(input: {id: "gid://shopify/Product/6975310463182"})
{
deletedProductId
}
}
QUERY;
$response = $client->query(["query" => $query]);
print_r($response);
die;
- 3 回答
- 0 關(guān)注
- 223 瀏覽
添加回答
舉報(bào)