Skip to content

Commit

Permalink
ENGCOM-4358: Adding property mapper for product eav attribute -> sear…
Browse files Browse the repository at this point in the history
…ch weight. #17668
  • Loading branch information
sidolov authored Mar 5, 2019
2 parents 8db78c8 + af0183c commit 302ec3c
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CatalogSearch\Model\ResourceModel\Setup;

use Magento\Eav\Model\Entity\Setup\PropertyMapperAbstract;

/**
* Class PropertyMapper
*
* @package Magento\CatalogSearch\Model\ResourceModel\Setup
*/
class PropertyMapper extends PropertyMapperAbstract
{
/**
* Map input attribute properties to storage representation
*
* @param array $input
* @param int $entityTypeId
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function map(array $input, $entityTypeId): array
{
return [
'search_weight' => $this->_getValue($input, 'search_weight', 1),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CatalogSearch\Test\Unit\Model\ResourceModel\Setup;

use Magento\CatalogSearch\Model\ResourceModel\Setup\PropertyMapper;
use PHPUnit\Framework\TestCase;

/**
* Class PropertyMapperTest
*
* @package Magento\CatalogSearch\Test\Unit\Model\ResourceModel\Setup
*/
class PropertyMapperTest extends TestCase
{
/**
* @var PropertyMapper
*/
private $propertyMapper;

/**
* @return void
*/
protected function setUp(): void
{
$this->propertyMapper = new PropertyMapper();
}

/**
* @return array
*/
public function caseProvider(): array
{
return [
[
['search_weight' => 9, 'something_other' => '3'],
['search_weight' => 9]
],
[
['something' => 3],
['search_weight' => 1]
]
];
}

/**
* @dataProvider caseProvider
*
* @test
*
* @param array $input
* @param array $result
* @return void
*/
public function testMapCorrectlyMapsValue(array $input, array $result): void
{
//Second parameter doesn't matter as it is not used
$this->assertSame($result, $this->propertyMapper->map($input, 4));
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/CatalogSearch/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,11 @@
<type name="Magento\Config\Model\Config">
<plugin name="config_enable_eav_indexer" type="Magento\CatalogSearch\Plugin\EnableEavIndexer" />
</type>
<type name="Magento\Eav\Model\Entity\Setup\PropertyMapper\Composite">
<arguments>
<argument name="propertyMappers" xsi:type="array">
<item name="catalog_search" xsi:type="string">Magento\CatalogSearch\Model\ResourceModel\Setup\PropertyMapper</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit 302ec3c

Please sign in to comment.