From 3af54ed66b83e0aa70f49e59ae9c34040c50691e Mon Sep 17 00:00:00 2001 From: Romain Ruaud Date: Thu, 9 Mar 2017 17:26:08 +0100 Subject: [PATCH] Prevent the getDefaultStoreView call to fail when browsing adminhtml with a restricted account. --- .../Rule/Condition/Product/AttributeList.php | 18 +++++++++++++++++- .../Catalog/Category/DataProviderPlugin.php | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Product/AttributeList.php b/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Product/AttributeList.php index 9b722933f..6920ef98d 100644 --- a/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Product/AttributeList.php +++ b/src/module-elasticsuite-catalog-rule/Model/Rule/Condition/Product/AttributeList.php @@ -172,7 +172,7 @@ public function getField($attributeName) private function getMapping() { if ($this->mapping === null) { - $defaultStore = $this->storeManager->getDefaultStoreView(); + $defaultStore = $this->getDefaultStoreView(); $index = $this->indexManager->getIndexByName($this->indexName, $defaultStore); $this->mapping = $index->getType($this->typeName)->getMapping(); @@ -180,4 +180,20 @@ private function getMapping() return $this->mapping; } + + /** + * Retrieve default Store View + * + * @return \Magento\Store\Api\Data\StoreInterface + */ + private function getDefaultStoreView() + { + $store = $this->storeManager->getDefaultStoreView(); + if (null === $store) { + // Occurs when current user does not have access to default website (due to AdminGWS ACLS on Magento EE). + $store = current($this->storeManager->getWebsites())->getDefaultStore(); + } + + return $store; + } } diff --git a/src/module-elasticsuite-virtual-category/Plugin/Catalog/Category/DataProviderPlugin.php b/src/module-elasticsuite-virtual-category/Plugin/Catalog/Category/DataProviderPlugin.php index abc5bbadd..897efdd93 100644 --- a/src/module-elasticsuite-virtual-category/Plugin/Catalog/Category/DataProviderPlugin.php +++ b/src/module-elasticsuite-virtual-category/Plugin/Catalog/Category/DataProviderPlugin.php @@ -107,7 +107,7 @@ private function getProductSorterLoadUrl(Category $category) $storeId = $category->getStoreId(); if ($storeId === 0) { - $defaultStoreId = $this->storeManager->getDefaultStoreView()->getId(); + $defaultStoreId = $this->getDefaultStoreView()->getId(); $storeId = current(array_filter($category->getStoreIds())); if (in_array($defaultStoreId, $category->getStoreIds())) { $storeId = $defaultStoreId; @@ -136,4 +136,20 @@ private function getProductSavedPositions(Category $category) return json_encode($productPositions, JSON_FORCE_OBJECT); } + + /** + * Retrieve default Store View + * + * @return \Magento\Store\Api\Data\StoreInterface + */ + private function getDefaultStoreView() + { + $store = $this->storeManager->getDefaultStoreView(); + if (null === $store) { + // Occurs when current user does not have access to default website (due to AdminGWS ACLS on Magento EE). + $store = current($this->storeManager->getWebsites())->getDefaultStore(); + } + + return $store; + } }