Skip to content

Commit af0183c

Browse files
ENGCOM-4358: Adding property mapper for product eav attribute -> search weight. #17668
- Merge Pull Request #17668 from bartoszkubicki/magento2:search-weight-property-mapper - Merged commits: 1. 83fa42d
2 parents 94383aa + 83fa42d commit af0183c

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
9+
namespace Magento\CatalogSearch\Model\ResourceModel\Setup;
10+
11+
use Magento\Eav\Model\Entity\Setup\PropertyMapperAbstract;
12+
13+
/**
14+
* Class PropertyMapper
15+
*
16+
* @package Magento\CatalogSearch\Model\ResourceModel\Setup
17+
*/
18+
class PropertyMapper extends PropertyMapperAbstract
19+
{
20+
/**
21+
* Map input attribute properties to storage representation
22+
*
23+
* @param array $input
24+
* @param int $entityTypeId
25+
* @return array
26+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
27+
*/
28+
public function map(array $input, $entityTypeId): array
29+
{
30+
return [
31+
'search_weight' => $this->_getValue($input, 'search_weight', 1),
32+
];
33+
}
34+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
9+
namespace Magento\CatalogSearch\Test\Unit\Model\ResourceModel\Setup;
10+
11+
use Magento\CatalogSearch\Model\ResourceModel\Setup\PropertyMapper;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Class PropertyMapperTest
16+
*
17+
* @package Magento\CatalogSearch\Test\Unit\Model\ResourceModel\Setup
18+
*/
19+
class PropertyMapperTest extends TestCase
20+
{
21+
/**
22+
* @var PropertyMapper
23+
*/
24+
private $propertyMapper;
25+
26+
/**
27+
* @return void
28+
*/
29+
protected function setUp(): void
30+
{
31+
$this->propertyMapper = new PropertyMapper();
32+
}
33+
34+
/**
35+
* @return array
36+
*/
37+
public function caseProvider(): array
38+
{
39+
return [
40+
[
41+
['search_weight' => 9, 'something_other' => '3'],
42+
['search_weight' => 9]
43+
],
44+
[
45+
['something' => 3],
46+
['search_weight' => 1]
47+
]
48+
];
49+
}
50+
51+
/**
52+
* @dataProvider caseProvider
53+
*
54+
* @test
55+
*
56+
* @param array $input
57+
* @param array $result
58+
* @return void
59+
*/
60+
public function testMapCorrectlyMapsValue(array $input, array $result): void
61+
{
62+
//Second parameter doesn't matter as it is not used
63+
$this->assertSame($result, $this->propertyMapper->map($input, 4));
64+
}
65+
}

app/code/Magento/CatalogSearch/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,11 @@
340340
<type name="Magento\Config\Model\Config">
341341
<plugin name="config_enable_eav_indexer" type="Magento\CatalogSearch\Plugin\EnableEavIndexer" />
342342
</type>
343+
<type name="Magento\Eav\Model\Entity\Setup\PropertyMapper\Composite">
344+
<arguments>
345+
<argument name="propertyMappers" xsi:type="array">
346+
<item name="catalog_search" xsi:type="string">Magento\CatalogSearch\Model\ResourceModel\Setup\PropertyMapper</item>
347+
</argument>
348+
</arguments>
349+
</type>
343350
</config>

0 commit comments

Comments
 (0)