|
7 | 7 | namespace Magento\CatalogSearch\Setup;
|
8 | 8 |
|
9 | 9 |
|
10 |
| -use Magento\Framework\DB\Adapter\AdapterInterface; |
| 10 | +use Magento\Catalog\Api\ProductAttributeRepositoryInterface; |
| 11 | +use Magento\Framework\Setup\InstallDataInterface; |
11 | 12 | use Magento\Framework\Setup\ModuleContextInterface;
|
12 | 13 | use Magento\Framework\Setup\ModuleDataSetupInterface;
|
13 | 14 |
|
14 |
| -class InstallData implements \Magento\Framework\Setup\InstallDataInterface |
| 15 | +class InstallData implements InstallDataInterface |
15 | 16 | {
|
| 17 | + /** |
| 18 | + * @var ProductAttributeRepositoryInterface |
| 19 | + */ |
| 20 | + private $attributeRepository; |
| 21 | + |
| 22 | + /** |
| 23 | + * @param ProductAttributeRepositoryInterface $attributeRepository |
| 24 | + */ |
| 25 | + public function __construct(ProductAttributeRepositoryInterface $attributeRepository) |
| 26 | + { |
| 27 | + $this->attributeRepository = $attributeRepository; |
| 28 | + } |
| 29 | + |
16 | 30 | /**
|
17 | 31 | * @param ModuleDataSetupInterface $setup
|
18 | 32 | * @param ModuleContextInterface $context
|
| 33 | + * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
19 | 34 | */
|
20 | 35 | public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
|
21 | 36 | {
|
22 |
| - $connection = $setup->getConnection(); |
23 |
| - $this->setWeight('sku', 6, $connection); |
24 |
| - $this->setWeight('name', 5, $connection); |
| 37 | + $this->setWeight('sku', 6); |
| 38 | + $this->setWeight('name', 5); |
25 | 39 | }
|
26 | 40 |
|
27 |
| - |
28 | 41 | /**
|
29 | 42 | * @param string $attributeCode
|
30 | 43 | * @param int $weight
|
31 |
| - * @param AdapterInterface $connection |
32 |
| - * @internal param $oldWeight |
| 44 | + * @internal param AdapterInterface $connection |
33 | 45 | */
|
34 |
| - private function setWeight($attributeCode, $weight, AdapterInterface $connection) |
| 46 | + private function setWeight($attributeCode, $weight) |
35 | 47 | {
|
36 |
| - $updateQuery = 'UPDATE catalog_eav_attribute SET search_weight = ?' |
37 |
| - . ' WHERE attribute_id =' |
38 |
| - . ' (SELECT eav_attribute.attribute_id FROM eav_attribute' |
39 |
| - . ' LEFT JOIN eav_entity_type ON eav_attribute.entity_type_id = eav_entity_type.entity_type_id' |
40 |
| - . ' WHERE eav_entity_type.entity_type_code = ?' |
41 |
| - . ' AND eav_attribute.attribute_code = ?)'; |
42 |
| - $bindings = [$weight, 'catalog_product', $attributeCode]; |
43 |
| - |
44 |
| - $connection->query($updateQuery, $bindings); |
| 48 | + $attribute = $this->attributeRepository->get($attributeCode); |
| 49 | + $attribute->setSearchWeight($weight); |
| 50 | + $this->attributeRepository->save($attribute); |
45 | 51 | }
|
46 | 52 | }
|
0 commit comments