From 0150e85a248be5c2066d16b6ea8339b3128c75c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20FOUCRET?= Date: Wed, 5 Sep 2018 11:41:06 +0200 Subject: [PATCH] Fix detection of the default store id in search API. --- .../Model/Search/RequestBuilder.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/module-elasticsuite-core/Model/Search/RequestBuilder.php b/src/module-elasticsuite-core/Model/Search/RequestBuilder.php index c634fa4cd..e2890b855 100644 --- a/src/module-elasticsuite-core/Model/Search/RequestBuilder.php +++ b/src/module-elasticsuite-core/Model/Search/RequestBuilder.php @@ -79,7 +79,8 @@ public function __construct( */ public function getRequest(\Magento\Framework\Api\Search\SearchCriteriaInterface $searchCriteria) { - $storeId = $this->storeManager->getStore()->getId(); + $storeId = $this->getCurrentStoreId(); + $containerName = $searchCriteria->getRequestName(); $containerConfiguration = $this->getSearchContainerConfiguration($storeId, $containerName); @@ -96,6 +97,22 @@ public function getRequest(\Magento\Framework\Api\Search\SearchCriteriaInterface return $this->searchRequestBuilder->create($storeId, $containerName, $from, $size, $queryText, $sortOrders, $filters, [], $facets); } + /** + * Return current store id. + * + * @return integer + */ + private function getCurrentStoreId() + { + $storeId = $this->storeManager->getStore()->getId(); + + if ($storeId == 0) { + $storeId = $this->storeManager->getDefaultStoreView()->getId(); + } + + return $storeId; + } + /** * Extract fulltext search query from search criteria. *