optimize data retrieve by customfields und enricher

This commit is contained in:
team 1
2026-04-13 16:11:19 +02:00
parent 0a05ccaee3
commit f7685c6fb5
10 changed files with 234 additions and 32 deletions

View File

@@ -7,6 +7,11 @@ namespace App\Commerce;
use App\Commerce\Dto\ShopProductResult;
use App\Shopware\ShopwareCriteriaBuilder;
use App\Shopware\StoreApiClient;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
final readonly class ShopSearchService
{
@@ -29,12 +34,18 @@ final readonly class ShopSearchService
if (!$this->enabled) {
return [];
}
$response = [];
$query = $this->queryParser->parse($originalPrompt, $commerceIntent);
$criteria = $this->criteriaBuilder->build($query, $this->maxResults);
$response = $this->storeApiClient->searchProducts($criteria);
try {
$response = $this->storeApiClient->searchProducts($criteria);
} catch (ClientExceptionInterface|DecodingExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface|TransportExceptionInterface $e) {
return $this->mapProducts($response);
}
$result = $this->mapProducts($response);;
return $result;
}
/**
@@ -63,6 +74,8 @@ final readonly class ShopSearchService
url: $this->baseUrl . $this->extractUrl($row),
highlights: $this->extractHighlights($row),
description: $this->cleanUpDescription($row),
productImage: $row['cover']['media']['thumbnails'][0]['url'] ?? 'no-image',
customFields: $this->getRelevantCustomFields($row['customFields'])
);
}
@@ -72,6 +85,15 @@ final readonly class ShopSearchService
));
}
private function getRelevantCustomFields($customField): string
{
$result = ($customField['migration_Backup_product_attr1'] ?? '') . ': ' . ($customField['migration_Backup_product_attr2'] ?? '');
$result .= ' | Einsatzgebiete: ' . ($customField['migration_Backup_product_attr4'] ?? '');
$result .= ' | Sprachen: ' . ($customField['migration_Backup_product_attr5'] ?? '');
return $result;
}
private function cleanUpDescription($description): string
{
if (isset($description['translated']['description'])) {