亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel + Shopify inventoryBulkAdjustQuantity

Laravel + Shopify inventoryBulkAdjustQuantity

PHP
一只名叫tom的貓 2023-05-12 10:35:05
我正在使用以下包:'osiset/Basic-Shopify-API' 并且需要按位置批量更新產品。只有使用 GraphQL 才有可能。此功能應該有效:inventoryBulkAdjustQuantityAtLocation Shopify 文檔 $shop = 'example.myshopify.com';    $token = 'shppa_admin_api_token';    / Create options for the API    $options = new Options();    $options->setVersion('2020-04');     // Create the client and session    $api = new BasicShopifyAPI($options);    $api->setSession(new Session($shop, $token));     $products[0]['inventoryItemId'] = '33125243617303';    $products[0]['availableDelta'] = 2000;    $result = $api->graph(        'mutation inventoryBulkAdjustQuantityAtLocation($inventoryItemAdjustments: InventoryAdjustItemInput!,$locationId: ID!)                  {inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $InventoryAdjustItemInput, locationId: $locationId) {userErrors {field message } inventoryLevels { id }}}',        ['inventoryItemAdjustments' =>             $products        ],    );但我不明白如何使用它。誰能幫幫我?
查看完整描述

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    

    );


查看完整回答
反對 回復 2023-05-12
?
慕姐4208626

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

 );


查看完整回答
反對 回復 2023-05-12
?
鳳凰求蠱

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;


查看完整回答
反對 回復 2023-05-12
  • 3 回答
  • 0 關注
  • 233 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號