add new configs

This commit is contained in:
team 1
2026-04-15 08:46:26 +02:00
parent 8cac77ed31
commit 1815a42035
18 changed files with 508 additions and 309 deletions

View File

@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Shopware;
use RuntimeException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
@@ -15,18 +16,16 @@ final readonly class StoreApiClient
{
public function __construct(
private HttpClientInterface $httpClient,
private string $baseUrl,
private string $salesChannelAccessKey,
private int $timeoutSeconds = 5,
)
{
private string $baseUrl,
private string $salesChannelAccessKey,
private int $timeoutSeconds = 5,
) {
}
/**
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
* @throws ClientExceptionInterface
*/
public function searchProducts(array $criteria): array
@@ -44,10 +43,22 @@ final readonly class StoreApiClient
]);
$statusCode = $response->getStatusCode();
$content = $response->getContent(false);
if ($statusCode < 200 || $statusCode >= 300) {
return [];
throw new RuntimeException(sprintf(
'Shopware Store API request failed with status %d. Response: %s',
$statusCode,
mb_substr(trim($content), 0, 1000)
));
}
return $response->toArray(false);
$data = json_decode($content, true);
if (!is_array($data)) {
throw new RuntimeException('Shopware Store API returned invalid JSON.');
}
return $data;
}
}