Skip to content

Commit

Permalink
Merge pull request #3886 from magento-engcom/1-es6-stock-status-hotfix
Browse files Browse the repository at this point in the history
Elasticsearch6 support
 - Fixed bug with out of stock products indexation
  • Loading branch information
ishakhsuvarov authored Mar 13, 2019
2 parents 4e62277 + a93688a commit d4d35b5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 64 deletions.
16 changes: 11 additions & 5 deletions app/code/Magento/Elasticsearch/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class Config implements ClientOptionsInterface
*/
const ENGINE_NAME = 'elasticsearch';

private const ENGINE_NAME_5 = 'elasticsearch5';

/**
* Elasticsearch Entity type
*/
Expand Down Expand Up @@ -64,23 +62,31 @@ class Config implements ClientOptionsInterface
private $engineResolver;

/**
* Constructor
* Available Elasticsearch engines.
*
* @var array
*/
private $engineList;

/**
* @param ScopeConfigInterface $scopeConfig
* @param ClientResolver|null $clientResolver
* @param EngineResolverInterface|null $engineResolver
* @param string|null $prefix
* @param array $engineList
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
ClientResolver $clientResolver = null,
EngineResolverInterface $engineResolver = null,
$prefix = null
$prefix = null,
$engineList = []
) {
$this->scopeConfig = $scopeConfig;
$this->clientResolver = $clientResolver ?: ObjectManager::getInstance()->get(ClientResolver::class);
$this->engineResolver = $engineResolver ?: ObjectManager::getInstance()->get(EngineResolverInterface::class);
$this->prefix = $prefix ?: $this->clientResolver->getCurrentEngine();
$this->engineList = $engineList;
}

/**
Expand Down Expand Up @@ -138,7 +144,7 @@ public function getSearchConfigData($field, $storeId = null)
*/
public function isElasticsearchEnabled()
{
return in_array($this->engineResolver->getCurrentSearchEngine(), [self::ENGINE_NAME, self::ENGINE_NAME_5]);
return in_array($this->engineResolver->getCurrentSearchEngine(), $this->engineList);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions app/code/Magento/Elasticsearch/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
<preference for="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ConverterInterface" type="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\Converter" />
<preference for="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface" type="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\Converter" />
<preference for="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProviderInterface" type="Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\CompositeFieldProvider" />
<type name="Magento\Elasticsearch\Model\Config">
<arguments>
<argument name="engineList" xsi:type="array">
<item name="elasticsearch" xsi:type="string">elasticsearch</item>
<item name="elasticsearch5" xsi:type="string">elasticsearch5</item>
</argument>
</arguments>
</type>
<type name="Magento\Elasticsearch\Model\Adapter\FieldMapper\FieldMapperResolver">
<arguments>
<argument name="fieldMappers" xsi:type="array">
Expand Down
56 changes: 0 additions & 56 deletions app/code/Magento/Elasticsearch6/Model/Config.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Magento\Store\Model\ScopeInterface;
use Magento\Search\Model\QueryInterface;
use Magento\AdvancedSearch\Model\SuggestedQueriesInterface;
use Magento\Elasticsearch6\Model\Config;
use Magento\Elasticsearch\Model\Config;
use Magento\Elasticsearch\SearchAdapter\ConnectionManager;
use Magento\Search\Model\QueryResultFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SuggestionsTest extends \PHPUnit\Framework\TestCase
*/
protected function setUp()
{
$this->config = $this->getMockBuilder(\Magento\Elasticsearch6\Model\Config::class)
$this->config = $this->getMockBuilder(\Magento\Elasticsearch\Model\Config::class)
->disableOriginalConstructor()
->setMethods(['isElasticsearchEnabled'])
->getMock();
Expand Down
10 changes: 9 additions & 1 deletion app/code/Magento/Elasticsearch6/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Elasticsearch\Model\Config">
<arguments>
<argument name="engineList" xsi:type="array">
<item name="elasticsearch6" xsi:type="string">elasticsearch6</item>
</argument>
</arguments>
</type>

<type name="Magento\Search\Model\Adminhtml\System\Config\Source\Engine">
<arguments>
<argument name="engines" xsi:type="array">
Expand Down Expand Up @@ -44,7 +52,7 @@
<item name="elasticsearch6" xsi:type="string">\Magento\Elasticsearch6\Model\Client\ElasticsearchFactory</item>
</argument>
<argument name="clientOptions" xsi:type="array">
<item name="elasticsearch6" xsi:type="string">\Magento\Elasticsearch6\Model\Config</item>
<item name="elasticsearch6" xsi:type="string">\Magento\Elasticsearch\Model\Config</item>
</argument>
</arguments>
</type>
Expand Down

0 comments on commit d4d35b5

Please sign in to comment.