Skip to content

Commit

Permalink
Refactor code, resolving PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand-soprex committed Aug 5, 2024
1 parent 2f1fbba commit b8888df
Showing 1 changed file with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
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;
use Shopware\Core\Content\Product\SalesChannel\Listing\Processor\CompositeListingProcessor;
use Shopware\Core\Content\Product\SalesChannel\Listing\ProductListingResult;
use Shopware\Core\Content\Product\SalesChannel\ProductAvailableFilter;
Expand All @@ -32,13 +35,15 @@ class ProductSearchRoute extends AbstractProductSearchRoute
use SearchResultHelper;

public function __construct(
private readonly AbstractProductSearchRoute $decorated,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly AbstractProductSearchRoute $decorated,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly ProductSearchBuilderInterface $searchBuilder,
private readonly SalesChannelRepository $salesChannelProductRepository,
private readonly CompositeListingProcessor $listingProcessor,
private readonly ConfigProvider $configProvider,
) {
private readonly SalesChannelRepository $salesChannelProductRepository,
private readonly CompositeListingProcessor $listingProcessor,
private readonly ConfigProvider $configProvider,
private readonly LoggerInterface $logger
)
{
}

public function getDecorated(): AbstractProductSearchRoute
Expand All @@ -47,10 +52,11 @@ public function getDecorated(): AbstractProductSearchRoute
}

public function load(
Request $request,
Request $request,
SalesChannelContext $context,
Criteria $criteria,
): ProductSearchRouteResponse {
Criteria $criteria,
): ProductSearchRouteResponse
{
try {
if (!SearchHelper::shouldHandleRequest($context, $this->configProvider)) {
return $this->decorated->load($request, $context, $criteria);
Expand Down Expand Up @@ -84,17 +90,27 @@ 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);
}
}

private function fetchProductsById(
Criteria $criteria,
Criteria $criteria,
SalesChannelContext $salesChannelContext,
?string $query,
): EntitySearchResult {
?string $query,
): EntitySearchResult
{
if (empty($criteria->getIds())) {
return $this->createEmptySearchResult($criteria, $salesChannelContext->getContext());
}
Expand Down

0 comments on commit b8888df

Please sign in to comment.