optimize data retrieve by customfields und enricher
This commit is contained in:
@@ -10,15 +10,18 @@ final readonly class ShopProductResult
|
||||
* @param string[] $highlights
|
||||
*/
|
||||
public function __construct(
|
||||
public string $id,
|
||||
public string $name,
|
||||
public string $id,
|
||||
public string $name,
|
||||
public ?string $productNumber = null,
|
||||
public ?string $manufacturer = null,
|
||||
public ?string $price = null,
|
||||
public ?bool $available = null,
|
||||
public ?bool $available = null,
|
||||
public ?string $url = null,
|
||||
public array $highlights = [],
|
||||
public ?string $description = null
|
||||
) {
|
||||
public array $highlights = [],
|
||||
public ?string $description = null,
|
||||
public ?string $productImage = null,
|
||||
public ?string $customFields = null,
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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'])) {
|
||||
|
||||
Reference in New Issue
Block a user