Skip to content

Commit

Permalink
Merge pull request Smile-SA#72 from Elastic-Suite/fix_explain-scope
Browse files Browse the repository at this point in the history
Fix Smile-SA#71 by injecting proper store scope in explain.
  • Loading branch information
romainruaud authored Sep 17, 2021
2 parents e6f3141 + 2d8474d commit 3840239
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,8 @@
/**
* Explain Adminhtml Index controller.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
* @category Smile
* @package Smile\ElasticsuiteExplain
* @author Romain Ruaud <[email protected]>
Expand Down Expand Up @@ -71,6 +74,11 @@ class Results extends Action
*/
private $searchContext;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;

/**
* Constructor.
*
Expand All @@ -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,
Expand All @@ -91,7 +100,8 @@ public function __construct(
ContainerConfigurationFactory $containerConfigFactory,
JsonHelper $jsonHelper,
QueryFactory $queryFactory,
ContextInterface $searchContext
ContextInterface $searchContext,
StoreManagerInterface $storeManager
) {
parent::__construct($context);

Expand All @@ -102,6 +112,7 @@ public function __construct(
$this->jsonHelper = $jsonHelper;
$this->queryFactory = $queryFactory;
$this->searchContext = $searchContext;
$this->storeManager = $storeManager;
}

/**
Expand Down Expand Up @@ -139,6 +150,7 @@ private function getResultObject()
$containerConfig = $this->getContainerConfiguration();

$this->updateSearchContext($this->getStoreId(), $category, $queryText);
$this->updateStoreContext($this->getStoreId());

return $this->resultModelFactory->create(
[
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 3840239

Please sign in to comment.