Skip to content

Commit

Permalink
Merge pull request #83 from magento-epam/2.3-develop
Browse files Browse the repository at this point in the history
Merge 2.3-develop to EPAM-PR-2
  • Loading branch information
nikshostko authored Aug 25, 2018
2 parents fb0b234 + adfa7cb commit 9144c43
Show file tree
Hide file tree
Showing 42 changed files with 1,994 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<waitForLoadingMaskToDisappear stepKey="waitForLoading2" />
<see selector="{{ProductDescriptionWYSIWYGToolbarSection.CancelBtn}}" userInput="Cancel" stepKey="seeCancelBtn1" />
<see selector="{{ProductDescriptionWYSIWYGToolbarSection.CreateFolder}}" userInput="Create Folder" stepKey="seeCreateFolderBtn1" />
<see selector="{{ProductDescriptionWYSIWYGToolbarSection.InsertFile}}" userInput="Add Selected" stepKey="seeAddSelectedBtn1" />
<dontSeeElement selector="{{ProductDescriptionWYSIWYGToolbarSection.InsertFile}}" stepKey="dontSeeAddSelectedBtn" />
<click selector="{{ProductDescriptionWYSIWYGToolbarSection.CreateFolder}}" stepKey="createFolder1"/>
<waitForElementVisible selector="{{ProductDescriptionWYSIWYGToolbarSection.FolderName}}" stepKey="waitForPopUp1" />
<fillField selector="{{ProductDescriptionWYSIWYGToolbarSection.FolderName}}" userInput="{{ImageFolder.name}}" stepKey="fillFolderName1" />
Expand All @@ -60,6 +60,7 @@
<click selector="{{ProductDescriptionWYSIWYGToolbarSection.confirmDelete}}" stepKey="confirmDelete1" />
<waitForElementNotVisible selector="{{ProductDescriptionWYSIWYGToolbarSection.image(ImageUpload1.value)}}" stepKey="waitForImageDeleted1" />
<dontSeeElement selector="{{ProductDescriptionWYSIWYGToolbarSection.image(ImageUpload1.value)}}" stepKey="dontSeeImage1" />
<dontSeeElement selector="{{ProductDescriptionWYSIWYGToolbarSection.InsertFile}}" stepKey="dontSeeAddSelectedBtn1" />
<attachFile selector="{{ProductDescriptionWYSIWYGToolbarSection.BrowseUploadImage}}" userInput="{{ImageUpload1.value}}" stepKey="uploadImage2"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoading6" />
<waitForElementVisible selector="{{ProductDescriptionWYSIWYGToolbarSection.image(ImageUpload1.value)}}" stepKey="waitForUploadImage2" />
Expand All @@ -78,7 +79,7 @@
<waitForLoadingMaskToDisappear stepKey="waitForLoading8" />
<see selector="{{ProductShortDescriptionWYSIWYGToolbarSection.CancelBtn}}" userInput="Cancel" stepKey="seeCancelBtn2" />
<see selector="{{ProductShortDescriptionWYSIWYGToolbarSection.CreateFolder}}" userInput="Create Folder" stepKey="seeCreateFolderBtn2" />
<see selector="{{ProductShortDescriptionWYSIWYGToolbarSection.InsertFile}}" userInput="Add Selected" stepKey="seeAddSelectedBtn2" />
<dontSeeElement selector="{{ProductShortDescriptionWYSIWYGToolbarSection.InsertFile}}" stepKey="dontSeeAddSelectedBtn2" />
<attachFile selector="{{ProductShortDescriptionWYSIWYGToolbarSection.BrowseUploadImage}}" userInput="{{ImageUpload3.value}}" stepKey="uploadImage3"/>
<waitForElementVisible selector="{{ProductShortDescriptionWYSIWYGToolbarSection.image(ImageUpload3.value)}}" stepKey="waitForUploadImage3" />
<waitForLoadingMaskToDisappear stepKey="waitForLoading9" />
Expand All @@ -88,6 +89,7 @@
<click selector="{{ProductShortDescriptionWYSIWYGToolbarSection.DeleteSelectedBtn}}" stepKey="clickDeleteSelected2" />
<waitForText userInput="OK" stepKey="waitForConfirm3" />
<click selector="{{ProductShortDescriptionWYSIWYGToolbarSection.confirmDelete}}" stepKey="confirmDelete2" />
<dontSeeElement selector="{{ProductDescriptionWYSIWYGToolbarSection.InsertFile}}" stepKey="dontSeeAddSelectedBtn3" />
<attachFile selector="{{ProductShortDescriptionWYSIWYGToolbarSection.BrowseUploadImage}}" userInput="{{ImageUpload3.value}}" stepKey="uploadImage4"/>
<waitForLoadingMaskToDisappear stepKey="waitForLoading10" />
<waitForElementVisible selector="{{ProductShortDescriptionWYSIWYGToolbarSection.image(ImageUpload3.value)}}" stepKey="waitForUploadImage4" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function _construct()

$this->buttonList->add(
'insert_files',
['class' => 'save no-display primary', 'label' => __('Add Selected'), 'type' => 'button'],
['class' => 'save no-display action-primary', 'label' => __('Add Selected'), 'type' => 'button'],
0,
0,
'header'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<waitForLoadingMaskToDisappear stepKey="waitForLoading2" />
<see selector="{{MediaGallerySection.CancelBtn}}" userInput="Cancel" stepKey="seeCancelBtn" />
<see selector="{{MediaGallerySection.CreateFolder}}" userInput="Create Folder" stepKey="seeCreateFolderBtn" />
<see selector="{{MediaGallerySection.InsertFile}}" userInput="Add Selected" stepKey="seeAddSelectedBtn" />
</actionGroup>
<actionGroup name="CreateImageFolder">
<arguments>
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Config/Model/Config/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ protected function _createEmptyElement(array $pathParts)
public function getFieldPathsByAttribute($attributeName, $attributeValue)
{
$result = [];
if (empty($this->_data['sections'])) {
return $result;
}

foreach ($this->_data['sections'] as $section) {
if (!isset($section['children'])) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public function addFieldsMapping(array $fields, $index, $entityType)
'match_mapping_type' => 'string',
'mapping' => [
'type' => 'float',
'store' => true,
],
],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Elasticsearch\Elasticsearch5\SearchAdapter\Aggregation;

use Magento\Framework\Search\Dynamic\IntervalInterface;
use Magento\Elasticsearch\SearchAdapter\ConnectionManager;
use Magento\Elasticsearch\Model\Adapter\FieldMapperInterface;
use Magento\Elasticsearch\Model\Config;
use Magento\Elasticsearch\SearchAdapter\SearchIndexNameResolver;
use Magento\CatalogSearch\Model\Indexer\Fulltext;

/**
* Aggregate price intervals for search query result.
*/
class Interval implements IntervalInterface
{
/**
* Minimal possible value
*/
const DELTA = 0.005;

/**
* @var ConnectionManager
*/
private $connectionManager;

/**
* @var FieldMapperInterface
*/
private $fieldMapper;

/**
* @var Config
*/
private $clientConfig;

/**
* @var string
*/
private $fieldName;

/**
* @var string
*/
private $storeId;

/**
* @var array
*/
private $entityIds;

/**
* @var SearchIndexNameResolver
*/
private $searchIndexNameResolver;

/**
* @param ConnectionManager $connectionManager
* @param FieldMapperInterface $fieldMapper
* @param Config $clientConfig
* @param SearchIndexNameResolver $searchIndexNameResolver
* @param string $fieldName
* @param string $storeId
* @param array $entityIds
*/
public function __construct(
ConnectionManager $connectionManager,
FieldMapperInterface $fieldMapper,
Config $clientConfig,
SearchIndexNameResolver $searchIndexNameResolver,
string $fieldName,
string $storeId,
array $entityIds
) {
$this->connectionManager = $connectionManager;
$this->fieldMapper = $fieldMapper;
$this->clientConfig = $clientConfig;
$this->fieldName = $fieldName;
$this->storeId = $storeId;
$this->entityIds = $entityIds;
$this->searchIndexNameResolver = $searchIndexNameResolver;
}

/**
* {@inheritdoc}
*/
public function load($limit, $offset = null, $lower = null, $upper = null)
{
$from = $to = [];
if ($lower) {
$from = ['gte' => $lower - self::DELTA];
}
if ($upper) {
$to = ['lt' => $upper - self::DELTA];
}

$requestQuery = $this->prepareBaseRequestQuery($from, $to);
$requestQuery = array_merge_recursive(
$requestQuery,
['body' => ['stored_fields' => [$this->fieldName], 'size' => $limit]]
);

if ($offset) {
$requestQuery['body']['from'] = $offset;
}

$queryResult = $this->connectionManager->getConnection()
->query($requestQuery);

return $this->arrayValuesToFloat($queryResult['hits']['hits'], $this->fieldName);
}

/**
* {@inheritdoc}
*/
public function loadPrevious($data, $index, $lower = null)
{
if ($lower) {
$from = ['gte' => $lower - self::DELTA];
}
if ($data) {
$to = ['lt' => $data - self::DELTA];
}

$requestQuery = $this->prepareBaseRequestQuery($from, $to);
$requestQuery = array_merge_recursive(
$requestQuery,
['size' => 0]
);

$queryResult = $this->connectionManager->getConnection()
->query($requestQuery);

$offset = $queryResult['hits']['total'];
if (!$offset) {
return false;
}

return $this->load($index - $offset + 1, $offset - 1, $lower);
}

/**
* {@inheritdoc}
*/
public function loadNext($data, $rightIndex, $upper = null)
{
$from = ['gt' => $data + self::DELTA];
$to = ['lt' => $data - self::DELTA];

$requestCountQuery = $this->prepareBaseRequestQuery($from, $to);
$requestCountQuery = array_merge_recursive(
$requestCountQuery,
['size' => 0]
);

$queryCountResult = $this->connectionManager->getConnection()
->query($requestCountQuery);

$offset = $queryCountResult['hits']['total'];
if (!$offset) {
return false;
}

$from = ['gte' => $data - self::DELTA];
if ($upper !== null) {
$to = ['lt' => $data - self::DELTA];
}

$requestQuery = $requestCountQuery;

$requestCountQuery['body']['query']['bool']['filter']['bool']['must']['range'] =
[$this->fieldName => array_merge($from, $to)];
$requestCountQuery['body']['from'] = $offset - 1;
$requestCountQuery['body']['size'] = $rightIndex - $offset + 1;
$queryResult = $this->connectionManager->getConnection()
->query($requestQuery);

return array_reverse($this->arrayValuesToFloat($queryResult['hits']['hits'], $this->fieldName));
}

/**
* Conver array values to float type.
*
* @param array $hits
* @param string $fieldName
*
* @return float[]
*/
private function arrayValuesToFloat(array $hits, string $fieldName): array
{
$returnPrices = [];
foreach ($hits as $hit) {
$returnPrices[] = (float)$hit['fields'][$fieldName][0];
}

return $returnPrices;
}

/**
* Prepare base query for search.
*
* @param array|null $from
* @param array|null $to
* @return array
*/
private function prepareBaseRequestQuery($from = null, $to = null): array
{
$requestQuery = [
'index' => $this->searchIndexNameResolver->getIndexName($this->storeId, Fulltext::INDEXER_ID),
'type' => $this->clientConfig->getEntityType(),
'body' => [
'stored_fields' => [
'_id',
],
'query' => [
'bool' => [
'must' => [
'match_all' => new \stdClass(),
],
'filter' => [
'bool' => [
'must' => [
[
'terms' => [
'_id' => $this->entityIds,
],
],
[
'range' => [
$this->fieldName => array_merge($from, $to),
],
],
],
],
],
],
],
'sort' => [
$this->fieldName,
],
],
];

return $requestQuery;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public function testAddFieldsMapping()
'product' => [
'_all' => [
'enabled' => true,
'type' => 'text'
'type' => 'text',
],
'properties' => [
'name' => [
Expand All @@ -356,7 +356,8 @@ public function testAddFieldsMapping()
'match' => 'price_*',
'match_mapping_type' => 'string',
'mapping' => [
'type' => 'float'
'type' => 'float',
'store' => true,
],
],
],
Expand All @@ -366,7 +367,7 @@ public function testAddFieldsMapping()
'match_mapping_type' => 'string',
'mapping' => [
'type' => 'text',
'index' => 'no'
'index' => 'no',
],
],
],
Expand All @@ -375,7 +376,7 @@ public function testAddFieldsMapping()
'match' => 'position_*',
'match_mapping_type' => 'string',
'mapping' => [
'type' => 'int'
'type' => 'int',
],
],
],
Expand Down Expand Up @@ -409,7 +410,7 @@ public function testAddFieldsMappingFailure()
'product' => [
'_all' => [
'enabled' => true,
'type' => 'text'
'type' => 'text',
],
'properties' => [
'name' => [
Expand All @@ -422,7 +423,8 @@ public function testAddFieldsMappingFailure()
'match' => 'price_*',
'match_mapping_type' => 'string',
'mapping' => [
'type' => 'float'
'type' => 'float',
'store' => true,
],
],
],
Expand All @@ -441,7 +443,7 @@ public function testAddFieldsMappingFailure()
'match' => 'position_*',
'match_mapping_type' => 'string',
'mapping' => [
'type' => 'int'
'type' => 'int',
],
],
],
Expand Down
Loading

0 comments on commit 9144c43

Please sign in to comment.