Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding property mapper for product eav attribute -> search weight. #17668

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>