feat: add ShopProClient::fetchCategories() method
This commit is contained in:
@@ -573,6 +573,40 @@ final class ShopProClient
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{ok:bool,http_code:int|null,message:string,categories:array<int,array<string,mixed>>}
|
||||
*/
|
||||
public function fetchCategories(
|
||||
string $baseUrl,
|
||||
string $apiKey,
|
||||
int $timeoutSeconds
|
||||
): array {
|
||||
$normalizedBaseUrl = rtrim(trim($baseUrl), '/');
|
||||
$endpointUrl = $normalizedBaseUrl . '/api.php?endpoint=categories&action=list';
|
||||
|
||||
$response = $this->requestJson($endpointUrl, $apiKey, $timeoutSeconds);
|
||||
if (($response['ok'] ?? false) !== true) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'http_code' => $response['http_code'] ?? null,
|
||||
'message' => (string) ($response['message'] ?? 'Nie mozna pobrac kategorii z shopPRO.'),
|
||||
'categories' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$data = is_array($response['data'] ?? null) ? $response['data'] : [];
|
||||
$categories = isset($data['categories']) && is_array($data['categories'])
|
||||
? $data['categories']
|
||||
: [];
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'http_code' => $response['http_code'] ?? null,
|
||||
'message' => '',
|
||||
'categories' => $categories,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $jsonBody
|
||||
* @return array{ok:bool,http_code:int|null,message:string,payload?:array<string,mixed>,data?:mixed}
|
||||
|
||||
Reference in New Issue
Block a user