Skip to content

Commit 7d70c60

Browse files
committed
MC-31304: [ElasticSearch] Exception on catalog search result page
1 parent 4b17fa1 commit 7d70c60

File tree

7 files changed

+33
-25
lines changed

7 files changed

+33
-25
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ public function updateIndexMapping(int $storeId, string $mappedIndexerId, string
387387
return $this;
388388
}
389389

390-
/** @var ProductAttributeInterface $attribute */
391390
$attribute = $this->productAttributeRepository->get($attributeCode);
392391
$newAttributeMapping = $this->staticFieldProvider->getField($attribute);
393392
$mappedAttributes = $this->getMappedAttributes($indexName);
@@ -410,7 +409,7 @@ public function updateIndexMapping(int $storeId, string $mappedIndexerId, string
410409
}
411410

412411
/**
413-
* Retrieve index definition from cache.
412+
* Retrieve index definition from class.
414413
*
415414
* @param int $storeId
416415
* @param string $mappedIndexerId
@@ -427,7 +426,7 @@ private function getIndexFromAlias(int $storeId, string $mappedIndexerId): strin
427426
}
428427

429428
/**
430-
* Retrieve mapped attributes from cache.
429+
* Retrieve mapped attributes from class.
431430
*
432431
* @param string $indexName
433432
* @return array
@@ -444,7 +443,7 @@ private function getMappedAttributes(string $indexName): array
444443
}
445444

446445
/**
447-
* Set mapped attributes to cache.
446+
* Set mapped attributes to class.
448447
*
449448
* @param string $indexName
450449
* @param array $mappedAttributes

app/code/Magento/Elasticsearch/Model/Adapter/FieldMapper/Product/FieldProvider/StaticField.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
namespace Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider;
99

10-
use Magento\Eav\Model\Config;
1110
use Magento\Catalog\Api\Data\ProductAttributeInterface;
11+
use Magento\Eav\Model\Config;
12+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1213
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider;
1314
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ConverterInterface
1415
as IndexTypeConverterInterface;
@@ -105,7 +106,6 @@ public function __construct(
105106
*/
106107
public function getFields(array $context = []): array
107108
{
108-
/** @var ProductAttributeInterface[] $attributes */
109109
$attributes = $this->eavConfig->getEntityAttributes(ProductAttributeInterface::ENTITY_TYPE_CODE);
110110
$allAttributes = [];
111111

@@ -124,10 +124,10 @@ public function getFields(array $context = []): array
124124
/**
125125
* Get field mapping for specific attribute.
126126
*
127-
* @param ProductAttributeInterface $attribute
127+
* @param AbstractAttribute $attribute
128128
* @return array
129129
*/
130-
public function getField(ProductAttributeInterface $attribute): array
130+
public function getField(AbstractAttribute $attribute): array
131131
{
132132
$fieldMapping = [];
133133
if (in_array($attribute->getAttributeCode(), $this->excludedAttributes, true)) {

app/code/Magento/Elasticsearch/Model/Indexer/Fulltext/Plugin/Category/Product/Attribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function afterSave(
102102
}
103103

104104
/**
105-
* Check if mapping needs to be updated (attribute is new).
105+
* Set class variables before saving attribute.
106106
*
107107
* @param AttributeResourceModel $subject
108108
* @param AbstractModel $attribute

app/code/Magento/Elasticsearch/Test/Unit/Model/Adapter/FieldMapper/Product/FieldProvider/StaticFieldTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace Magento\Elasticsearch\Test\Unit\Model\Adapter\FieldMapper\Product\FieldProvider;
99

10-
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1110
use Magento\Eav\Model\Config;
11+
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1212
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter;
1313
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeProvider;
1414
use Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\FieldProvider\FieldIndex\ConverterInterface
@@ -184,7 +184,7 @@ function ($attributeMock, $context) use ($fieldName, $compositeFieldName, $sortF
184184
}
185185
);
186186

187-
$productAttributeMock = $this->getMockBuilder(ProductAttributeInterface::class)
187+
$productAttributeMock = $this->getMockBuilder(AbstractAttribute::class)
188188
->setMethods(['getAttributeCode'])
189189
->disableOriginalConstructor()
190190
->getMockForAbstractClass();

app/code/Magento/Elasticsearch/Test/Unit/Model/Indexer/Fulltext/Plugin/Category/Product/AttributeTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,19 @@ protected function setUp(): void
8888
*/
8989
public function testAfterSave(bool $isNewObject, bool $isElasticsearchEnabled, array $dimensions): void
9090
{
91-
/** @var AttributeModel $attribute */
92-
$attribute = (new ObjectManager($this))->getObject(AttributeModel::class);
93-
$attribute->isObjectNew($isNewObject);
94-
$attribute->setAttributeCode('example_attribute_code');
91+
/** @var AttributeModel|MockObject $attributeMock */
92+
$attributeMock = $this->createMock(AttributeModel::class);
93+
$attributeMock->expects($this->once())
94+
->method('isObjectNew')
95+
->willReturn($isNewObject);
96+
97+
$attributeMock->expects($this->once())
98+
->method('getAttributeCode')
99+
->willReturn('example_attribute_code');
100+
95101
/** @var AttributeResourceModel|MockObject $subjectMock */
96102
$subjectMock = $this->createMock(AttributeResourceModel::class);
97-
$this->attributePlugin->beforeSave($subjectMock, $attribute);
103+
$this->attributePlugin->beforeSave($subjectMock, $attributeMock);
98104

99105
$indexerData = ['indexer_example_data'];
100106

@@ -133,7 +139,7 @@ public function testAfterSave(bool $isNewObject, bool $isElasticsearchEnabled, a
133139
->method('getIterator')
134140
->willReturn(new ArrayIterator($dimensions));
135141

136-
$this->attributePlugin->afterSave($subjectMock, $subjectMock);
142+
$this->assertEquals($subjectMock, $this->attributePlugin->afterSave($subjectMock, $subjectMock));
137143
}
138144

139145
/**

dev/tests/integration/testsuite/Magento/Catalog/_files/category_attribute.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
88

9-
use Magento\Catalog\Model\Category\Attribute;
9+
use Magento\Catalog\Model\Category\AttributeFactory;
1010
use Magento\TestFramework\Helper\Bootstrap;
1111

12-
$attribute = Bootstrap::getObjectManager()
13-
->create(Attribute::class);
12+
/** @var AttributeFactory $attributeFactory */
13+
$attributeFactory = Bootstrap::getObjectManager()->get(AttributeFactory::class);
14+
$attribute = $attributeFactory->create();
1415
$attribute->setAttributeCode('test_attribute_code_666')
1516
->setEntityTypeId(3)
1617
->setIsGlobal(1)

dev/tests/integration/testsuite/Magento/Catalog/_files/category_attribute_rollback.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66

77
/** @var Registry $registry */
88

9-
use Magento\Catalog\Model\Category\Attribute;
9+
use Magento\Catalog\Model\Category\AttributeFactory;
1010
use Magento\Framework\Registry;
1111
use Magento\TestFramework\Helper\Bootstrap;
1212

13-
$registry = Bootstrap::getObjectManager()->get(Registry::class);
13+
$objectManager = Bootstrap::getObjectManager();
14+
/** @var Registry $registry */
15+
$registry = $objectManager->get(Registry::class);
1416

1517
$registry->unregister('isSecureArea');
1618
$registry->register('isSecureArea', true);
1719

18-
/** @var Attribute $attribute */
19-
$attribute = Bootstrap::getObjectManager()
20-
->create(Attribute::class);
20+
/** @var AttributeFactory $attributeFactory */
21+
$attributeFactory = $objectManager->get(AttributeFactory::class);
22+
$attribute = $attributeFactory->create();
2123

2224
$attribute->loadByCode(3, 'test_attribute_code_666');
2325

0 commit comments

Comments
 (0)