Skip to content

Commit 704e082

Browse files
vgoncharenkoduhon
authored andcommitted
MAGETWO-94482: [2.3] Fixed procedure of creating mapping for dynamic fields in elasticsearch
- fix tests
1 parent 596ffb1 commit 704e082

File tree

53 files changed

+432
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+432
-139
lines changed

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public function getFields(array $productIds, $storeId)
7171
* @param int $productId
7272
* @param array $categoryIndexData
7373
* @return array
74-
* @throws \Magento\Framework\Exception\LocalizedException
7574
*/
7675
private function getProductCategoryData($productId, array $categoryIndexData)
7776
{

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/DataMapper/ProductDataMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ protected function getProductPriceData($productId, $storeId, array $priceIndexDa
390390
foreach ($productPriceIndexData as $customerGroupId => $price) {
391391
$fieldName = $this->fieldMapper->getFieldName(
392392
'price',
393-
['customerGroupId' => $customerGroupId]
393+
['customerGroupId' => $customerGroupId, 'websiteId' => $storeId]
394394
);
395395
$result[$fieldName] = sprintf('%F', $price);
396396
}

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldIndex/Converter.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex;
77

88
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ConverterInterface;
9+
use Magento\Framework\Exception\LocalizedException;
910

1011
/**
1112
* Field type converter from internal index type to elastic service.
@@ -27,10 +28,17 @@ class Converter implements ConverterInterface
2728
];
2829

2930
/**
30-
* {@inheritdoc}
31+
* Get service field index type for elasticsearch 5.
32+
*
33+
* @param string $internalType
34+
* @return string|boolean
35+
* @throws LocalizedException
3136
*/
3237
public function convert(string $internalType)
3338
{
39+
if (!isset($this->mapping[$internalType])) {
40+
throw new LocalizedException(__('Unsupported internal field index type: %1', $internalType));
41+
}
3442
return $this->mapping[$internalType];
3543
}
3644
}

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldIndex/IndexResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
as FieldTypeResolver;
1616

1717
/**
18-
* Field index resolver that provide index type for attribute in mapping.
19-
* For example we need to set 'no'/false in case when attribute must be present in index data,
18+
* Field index resolver that provides index type for the attribute in mapping.
19+
* For example, we need to set ‘no’/false in the case when attribute must be present in index data,
2020
* but stay as not indexable.
2121
*/
2222
class IndexResolver implements ResolverInterface

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Converter.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType;
77

88
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldType\ConverterInterface;
9+
use Magento\Framework\Exception\LocalizedException;
910

1011
/**
1112
* Field type converter from internal data types to elastic service.
@@ -36,10 +37,17 @@ class Converter implements ConverterInterface
3637
];
3738

3839
/**
39-
* {@inheritdoc}
40+
* Get service field type for elasticsearch 5.
41+
*
42+
* @param string $internalType
43+
* @return string
44+
* @throws LocalizedException
4045
*/
4146
public function convert(string $internalType): string
4247
{
48+
if (!isset($this->mapping[$internalType])) {
49+
throw new LocalizedException(__('Unsupported internal field type: %1', $internalType));
50+
}
4351
return $this->mapping[$internalType];
4452
}
4553
}

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Resolver/CompositeResolver.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ class CompositeResolver implements ResolverInterface
2424
*/
2525
public function __construct(array $items)
2626
{
27-
$this->items = $items;
27+
$this->items = (function (ResolverInterface ...$items) {
28+
return $items;
29+
})(...$items);
2830
}
2931

3032
/**
31-
* {@inheritdoc}
33+
* Get field type.
34+
*
35+
* @param AttributeAdapter $attribute
36+
* @return string
3237
*/
3338
public function getFieldType(AttributeAdapter $attribute): ?string
3439
{

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Resolver/IntegerType.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public function __construct(ConverterInterface $fieldTypeConverter, $integerType
3636
}
3737

3838
/**
39-
* {@inheritdoc}
39+
* Get integer field type.
40+
*
41+
* @param AttributeAdapter $attribute
42+
* @return string
4043
*/
4144
public function getFieldType(AttributeAdapter $attribute): ?string
4245
{

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/Product/FieldProvider/FieldType/Resolver/KeywordType.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public function __construct(ConverterInterface $fieldTypeConverter)
2929
}
3030

3131
/**
32-
* {@inheritdoc}
32+
* Get field type.
33+
*
34+
* @param AttributeAdapter $attribute
35+
* @return string
3336
*/
3437
public function getFieldType(AttributeAdapter $attribute): ?string
3538
{

app/code/Magento/Elasticsearch/Elasticsearch5/Model/Adapter/FieldMapper/ProductFieldMapper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ public function __construct(
107107
* @param string $attributeCode
108108
* @param array $context
109109
* @return string
110-
* @throws \Magento\Framework\Exception\LocalizedException
111110
*/
112111
public function getFieldName($attributeCode, $context = [])
113112
{

app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/CategoryFieldsProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ public function getFields(array $productIds, $storeId)
7171
* @param int $productId
7272
* @param array $categoryIndexData
7373
* @return array
74-
* @throws \Magento\Framework\Exception\LocalizedException
7574
*/
7675
private function getProductCategoryData($productId, array $categoryIndexData)
7776
{

0 commit comments

Comments
 (0)