forked from Smile-SA/elasticsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Smile-SA#72 from Elastic-Suite/fix_explain-scope
Fix Smile-SA#71 by injecting proper store scope in explain.
- Loading branch information
Showing
1 changed file
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
use Magento\Catalog\Api\Data\CategoryInterface; | ||
use Magento\Framework\Json\Helper\Data as JsonHelper; | ||
use Magento\Search\Model\QueryFactory; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Smile\ElasticsuiteCatalogOptimizer\Api\Data\OptimizerInterfaceFactory; | ||
use Smile\ElasticsuiteExplain\Model\ResultFactory as ResultModelFactory; | ||
use Smile\ElasticsuiteCore\Api\Search\ContextInterface; | ||
|
@@ -30,6 +31,8 @@ | |
/** | ||
* Explain Adminhtml Index controller. | ||
* | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteExplain | ||
* @author Romain Ruaud <[email protected]> | ||
|
@@ -71,6 +74,11 @@ class Results extends Action | |
*/ | ||
private $searchContext; | ||
|
||
/** | ||
* @var \Magento\Store\Model\StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
|
@@ -82,6 +90,7 @@ class Results extends Action | |
* @param JsonHelper $jsonHelper JSON Helper. | ||
* @param QueryFactory $queryFactory Query Factory. | ||
* @param ContextInterface $searchContext Search context. | ||
* @param StoreManagerInterface $storeManager Store Manager. | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
|
@@ -91,7 +100,8 @@ public function __construct( | |
ContainerConfigurationFactory $containerConfigFactory, | ||
JsonHelper $jsonHelper, | ||
QueryFactory $queryFactory, | ||
ContextInterface $searchContext | ||
ContextInterface $searchContext, | ||
StoreManagerInterface $storeManager | ||
) { | ||
parent::__construct($context); | ||
|
||
|
@@ -102,6 +112,7 @@ public function __construct( | |
$this->jsonHelper = $jsonHelper; | ||
$this->queryFactory = $queryFactory; | ||
$this->searchContext = $searchContext; | ||
$this->storeManager = $storeManager; | ||
} | ||
|
||
/** | ||
|
@@ -139,6 +150,7 @@ private function getResultObject() | |
$containerConfig = $this->getContainerConfiguration(); | ||
|
||
$this->updateSearchContext($this->getStoreId(), $category, $queryText); | ||
$this->updateStoreContext($this->getStoreId()); | ||
|
||
return $this->resultModelFactory->create( | ||
[ | ||
|
@@ -259,4 +271,19 @@ private function updateSearchContext($storeId, $category, $queryText) | |
$this->searchContext->setCurrentCategory($category); | ||
} | ||
} | ||
|
||
/** | ||
* Update the store manager current store. | ||
* This is due to the fact that some components might want to rely on $storeManager->getStore() later. | ||
* | ||
* @param integer $storeId Store id. | ||
* | ||
* @return void | ||
*/ | ||
private function updateStoreContext($storeId) | ||
{ | ||
$store = $this->storeManager->getStore($storeId); | ||
|
||
$this->storeManager->setCurrentStore($store); | ||
} | ||
} |