2 回答

TA貢獻1757條經(jīng)驗 獲得超7個贊
想出了解決辦法。以下代碼按產(chǎn)品 IDS 獲取所有產(chǎn)品的列表。該數(shù)組可用于根據(jù)要求設(shè)置數(shù)據(jù)(按 SKU 或任何內(nèi)容)
require 'vendor/autoload.php';
use Square\SquareClient;
use Square\LocationsApi;
use Square\Exceptions\ApiException;
use Square\Http\ApiResponse;
use Square\Models\ListLocationsResponse;
use Square\Environment;
$client = new SquareClient([
'accessToken' => '{{access_token}}',
'environment' => Environment::PRODUCTION,
]);
$bag = [];
$cursor = null;
$ctr = 1;
$api_response = $client->getCatalogApi()->listCatalog($cursor, 'ITEM');
if ($api_response->isSuccess()) {
$result = $api_response->getResult();
} else {
$errors = $api_response->getErrors();
}
$g1 = $result;
$g2 = json_encode($g1);
$g3 = json_decode($g2);
$cursor = $g3->cursor;
$objects = $g3->objects;
$g4 = json_encode($objects);
$g5 = json_decode($g4);
foreach($g5 as $g51){
$bag[$g51->id] = $g51;
}
while($cursor != null){
$api_response2 = $client->getCatalogApi()->listCatalog($cursor, 'ITEM');
if ($api_response2->isSuccess()) {
$result2 = $api_response2->getResult();
} else {
$errors2 = $api_response2->getErrors();
}
$g6 = $result2;
$g7 = json_encode($g6);
$g8 = json_decode($g7);
$cursor = $g8->cursor;
$objects2 = $g8->objects;
$g9 = json_encode($objects2);
$g10 = json_decode($g9);
foreach($g10 as $g101){
$bag[$g101->id] = $g101;
}
}
var_dump(count($bag));

TA貢獻1816條經(jīng)驗 獲得超6個贊
object_id
s 與 SKU 不同;它們是 Square 這邊生成的唯一 ID。您可能希望使用SearchCatalogObjects?(POST /v2/catalog/search) 端點來按 SKU 進行搜索。使用您的 SKU 之一的查詢示例如下:
{
? "query": {
? ? "exact_query": {
? ? ? "attribute_name": "sku",
? ? ? "attribute_value": "GFLR20L"
? ? }
? }
}
這將獲取您的目錄對象 ID,但如果您對庫存感興趣,您仍然需要使用另一個端點來獲取庫存,例如RetrieveInventoryCount(它以catalog_object_id
s 作為參數(shù))。
- 2 回答
- 0 關(guān)注
- 155 瀏覽
添加回答
舉報