From 9e74d0bc09b46da4f5c269e38c3d377c1f6404a0 Mon Sep 17 00:00:00 2001 From: Bojan Date: Mon, 5 Aug 2024 12:56:41 +0200 Subject: [PATCH] Refactor the code, PR comments --- .../SalesChannel/Search/ProductSearchRoute.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Decorator/Core/Content/Product/SalesChannel/Search/ProductSearchRoute.php b/src/Decorator/Core/Content/Product/SalesChannel/Search/ProductSearchRoute.php index 77b2694a..4384df68 100644 --- a/src/Decorator/Core/Content/Product/SalesChannel/Search/ProductSearchRoute.php +++ b/src/Decorator/Core/Content/Product/SalesChannel/Search/ProductSearchRoute.php @@ -8,6 +8,7 @@ use Nosto\NostoIntegration\Model\ConfigProvider; use Nosto\NostoIntegration\Traits\SearchResultHelper; use Nosto\NostoIntegration\Utils\SearchHelper; +use Psr\Log\LoggerInterface; use Shopware\Core\Content\Product\Aggregate\ProductVisibility\ProductVisibilityDefinition; use Shopware\Core\Content\Product\Events\ProductSearchResultEvent; use Shopware\Core\Content\Product\ProductEvents; @@ -40,6 +41,7 @@ public function __construct( private readonly SalesChannelRepository $salesChannelProductRepository, private readonly CompositeListingProcessor $listingProcessor, private readonly ConfigProvider $configProvider, + private readonly LoggerInterface $logger ) { } @@ -88,8 +90,17 @@ public function load( $this->listingProcessor->process($request, $productListing, $context); + $this->eventDispatcher->dispatch( + new ProductSearchResultEvent($request, $productListing, $context), + ProductEvents::PRODUCT_SEARCH_RESULT + ); + return new ProductSearchRouteResponse($productListing); - } catch (Exception) { + } catch (RoutingException $e) { + $this->logger->error('Routing exception occurred: ' . $e->getMessage()); + return $this->decorated->load($request, $context, $criteria); + } catch (Exception $e) { + $this->logger->error('An unexpected error occurred: ' . $e->getMessage()); return $this->decorated->load($request, $context, $criteria); } }