Skip to content

Commit

Permalink
Add Fallback Mechanism for Search and Category Page
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand-soprex committed Oct 30, 2024
1 parent 91ace44 commit e0dd7b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function load(
SalesChannelContext $context,
Criteria $criteria = null,
): ProductListingRouteResponse {
$originalRequest = clone $request;
$originalContext = clone $context;
$originalCriteria = clone $criteria;

$shouldHandleRequest = SearchHelper::shouldHandleRequest($context, $this->configProvider, true);

$isDefaultCategory = $categoryId === $context->getSalesChannel()->getNavigationCategoryId();
Expand Down Expand Up @@ -79,6 +83,11 @@ public function load(
$productListing = ProductListingResult::createFrom(
$this->fetchProductsById($criteria, $context),
);

if (!$productListing->getElements()) {
return $this->decorated->load($categoryId, $originalRequest, $originalContext, $originalCriteria);
}

$productListing->addCurrentFilter('navigationId', $categoryId);
$productListing->setStreamId($streamId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function load(
): ProductSearchRouteResponse
{
try {
$originalRequest = clone $request;
$originalContext = clone $context;
$originalCriteria = clone $criteria;

if (!SearchHelper::shouldHandleRequest($context, $this->configProvider)) {
return $this->decorated->load($request, $context, $criteria);
}
Expand Down Expand Up @@ -85,6 +89,11 @@ public function load(

$query = $request->query->get('search');
$result = $this->fetchProductsById($criteria, $context, $query);

if (!$result->getElements()) {
return $this->decorated->load($originalRequest, $originalContext, $originalCriteria);
}

$productListing = ProductListingResult::createFrom($result);
$productListing->addCurrentFilter('search', $query);

Expand Down

0 comments on commit e0dd7b7

Please sign in to comment.