Skip to content

Make definition of modules for which IntegerNet_solr is used explicit #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions main/src/Model/Plugin/AdapterFactoryPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ class AdapterFactoryPlugin
* @var LoggerInterface
*/
private $logger;
/**
* @var string[]
*/
private $searchResultModuleNames;
/**
* @var string[]
*/
private $categoryModuleNames;

/**
* @param ScopeConfigInterface $scopeConfig
Expand All @@ -73,7 +81,9 @@ public function __construct(
RequestInterface $request,
AllStoresConfig $solrConfig,
StoreManagerInterface $storeManager,
LoggerInterface $logger
LoggerInterface $logger,
array $searchResultModuleNames,
array $categoryModuleNames
) {
$this->scopeConfig = $scopeConfig;
$this->registry = $registry;
Expand All @@ -82,6 +92,8 @@ public function __construct(
$this->solrResource = new ResourceFacade($solrConfig->getArrayCopy());
$this->storeManager = $storeManager;
$this->logger = $logger;
$this->searchResultModuleNames = $searchResultModuleNames;
$this->categoryModuleNames = $categoryModuleNames;
}

/**
Expand All @@ -95,7 +107,10 @@ public function aroundCreate(AdapterFactory $subject, \Closure $proceed, $data =
if (!$this->scopeConfig->isSetFlag('integernet_solr/general/is_active')) {
return $proceed($data);
}
if ($this->request->getModuleName() == 'catalog'
if (!$this->isCategoryRequest() && !$this->isSearchResultRequest()) {
return $proceed($data);
}
if ($this->isCategoryRequest()
&& !$this->scopeConfig->isSetFlag('integernet_solr/category/is_active')) {
return $proceed($data);
}
Expand All @@ -117,4 +132,20 @@ private function canPingSolrServer($storeId)

return boolval($solr->ping());
}

/**
* @return bool
*/
private function isSearchResultRequest()
{
return in_array($this->request->getModuleName(), $this->searchResultModuleNames);
}

/**
* @return bool
*/
private function isCategoryRequest()
{
return in_array($this->request->getModuleName(), $this->categoryModuleNames);
}
}
10 changes: 10 additions & 0 deletions main/src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@

<!-- Plugins -->

<type name="IntegerNet\Solr\Model\Plugin\AdapterFactoryPlugin">
<arguments>
<argument name="searchResultModuleNames" xsi:type="array">
<item name="catalogsearch" xsi:type="string">catalogsearch</item>
</argument>
<argument name="categoryModuleNames" xsi:type="array">
<item name="catalog" xsi:type="string">catalog</item>
</argument>
</arguments>
</type>
<type name="Magento\Search\Model\AdapterFactory">
<plugin name="integernet_solr_choose_adapter" type="IntegerNet\Solr\Model\Plugin\AdapterFactoryPlugin" />
</type>
Expand Down