Skip to content

Commit

Permalink
Merge pull request #350 from romainruaud/fix_website-restrictions-adm…
Browse files Browse the repository at this point in the history
…inhtml

Prevent the getDefaultStoreView call to fail when browsing adminhtml …
  • Loading branch information
afoucret authored Mar 13, 2017
2 parents fd4fdf9 + 3af54ed commit 7e81ec4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,28 @@ 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();
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 7e81ec4

Please sign in to comment.