Skip to content

Commit 4ac1999

Browse files
committed
ACP2E-3892: [Mainline] Unpopulated pages are cached due to search engine errors
1 parent cea1491 commit 4ac1999

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
use Magento\Framework\Url\Helper\Data;
2929
use Magento\Framework\App\ObjectManager;
3030
use Magento\Catalog\Helper\Output as OutputHelper;
31-
use Magento\Framework\App\Response\Http as ResponseHttp;
31+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
3232

3333
/**
3434
* Product list
@@ -80,6 +80,11 @@ class ListProduct extends AbstractProduct implements IdentityInterface
8080
*/
8181
private ?array $specialPriceMap = null;
8282

83+
/**
84+
* @var CollectionFactory
85+
*/
86+
private CollectionFactory $productCollectionFactory;
87+
8388
/**
8489
* @param Context $context
8590
* @param PostHelper $postDataHelper
@@ -89,6 +94,7 @@ class ListProduct extends AbstractProduct implements IdentityInterface
8994
* @param array $data
9095
* @param OutputHelper|null $outputHelper
9196
* @param SpecialPriceBulkResolverInterface|null $specialPriceBulkResolver
97+
* @param CollectionFactory|null $collectionFactory
9298
*/
9399
public function __construct(
94100
Context $context,
@@ -98,7 +104,8 @@ public function __construct(
98104
Data $urlHelper,
99105
array $data = [],
100106
?OutputHelper $outputHelper = null,
101-
?SpecialPriceBulkResolverInterface $specialPriceBulkResolver = null
107+
?SpecialPriceBulkResolverInterface $specialPriceBulkResolver = null,
108+
?CollectionFactory $collectionFactory = null
102109
) {
103110
$this->_catalogLayer = $layerResolver->get();
104111
$this->_postDataHelper = $postDataHelper;
@@ -107,6 +114,8 @@ public function __construct(
107114
$this->specialPriceBulkResolver = $specialPriceBulkResolver ??
108115
ObjectManager::getInstance()->get(SpecialPriceBulkResolverInterface::class);
109116
$data['outputHelper'] = $outputHelper ?? ObjectManager::getInstance()->get(OutputHelper::class);
117+
$this->productCollectionFactory = $collectionFactory ??
118+
ObjectManager::getInstance()->get(CollectionFactory::class);
110119
parent::__construct(
111120
$context,
112121
$data
@@ -218,7 +227,9 @@ protected function _beforeToHtml()
218227
}
219228
} catch (\Throwable) {
220229
$this->setData('has_error', true);
221-
$this->_productCollection = [];
230+
$collection = $this->productCollectionFactory->create();
231+
$collection->addFieldToFilter('entity_id', ['in' => []]);
232+
$this->_productCollection = $collection;
222233
}
223234
}
224235

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/Search.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ public function getResult(
167167
]
168168
);
169169
}
170-
171170
}
172171

173172
/**

app/code/Magento/CatalogSearch/i18n/en_US.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,3 @@ name,name
4242
"This value must be compatible with the corresponding setting in the configured search engine.","This value must be compatible with the corresponding setting in the configured search engine."
4343
"If not specified, Default Search Engine will be used.","If not specified, Default Search Engine will be used."
4444
"This search engine option is no longer supported by Adobe. It is recommended to use OpenSearch as a search engine instead.","This search engine option is no longer supported by Adobe. It is recommended to use OpenSearch as a search engine instead."
45-
"Could not perform search","Could not perform search"

app/code/Magento/OpenSearch/SearchAdapter/Adapter.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\Search\RequestInterface;
1717
use Magento\Framework\Search\Response\QueryResponse;
1818
use Magento\Search\Model\Search\PageSizeProvider;
19+
use OpenSearch\Common\Exceptions\Missing404Exception;
1920
use Psr\Log\LoggerInterface;
2021

2122
/**
@@ -45,6 +46,23 @@ class Adapter implements AdapterInterface
4546
*/
4647
private AggregationBuilder $aggregationBuilder;
4748

49+
/**
50+
* Empty response from OpenSearch
51+
*
52+
* @var array
53+
*/
54+
private static $emptyRawResponse = [
55+
'hits' => [
56+
'hits' => []
57+
],
58+
'aggregations' => [
59+
'price_bucket' => [],
60+
'category_bucket' => [
61+
'buckets' => []
62+
]
63+
]
64+
];
65+
4866
/**
4967
* @var QueryContainerFactory
5068
*/
@@ -126,6 +144,9 @@ public function query(RequestInterface $request) : QueryResponse
126144
}
127145

128146
$rawResponse = $client->query($query);
147+
} catch (Missing404Exception $e) {
148+
$this->logger->critical($e);
149+
$rawResponse = self::$emptyRawResponse;
129150
} catch (\Exception $e) {
130151
$this->logger->critical($e);
131152
throw new ClientException($e->getMessage(), $e->getCode(), $e);

dev/tests/integration/testsuite/Magento/Elasticsearch/ElasticAdapter/SearchAdapter/AdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2018 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

0 commit comments

Comments
 (0)