第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Laravel + Shopify inventoryBulkAdjustQuantity

Laravel + Shopify inventoryBulkAdjustQuantity

PHP
一只名叫tom的貓 2023-05-12 10:35:05
我正在使用以下包:'osiset/Basic-Shopify-API' 并且需要按位置批量更新產(chǎn)品。只有使用 GraphQL 才有可能。此功能應(yīng)該有效: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        ],    );但我不明白如何使用它。誰(shuí)能幫幫我?
查看完整描述

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    

    );


查看完整回答
反對(duì) 回復(fù) 2023-05-12
?
慕姐4208626

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

 );


查看完整回答
反對(duì) 回復(fù) 2023-05-12
?
鳳凰求蠱

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;


查看完整回答
反對(duì) 回復(fù) 2023-05-12
  • 3 回答
  • 0 關(guān)注
  • 223 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)