19
19
namespace Magento \Catalog \Model \ResourceModel ;
20
20
21
21
use Exception ;
22
+ use Magento \Catalog \Api \Data \ProductInterface ;
23
+ use Magento \Eav \Api \Data \AttributeInterface ;
22
24
use Magento \Framework \App \ResourceConnection ;
25
+ use Magento \Framework \EntityManager \MetadataPool ;
23
26
use Magento \Framework \Exception \CouldNotSaveException ;
24
27
use Magento \Framework \Exception \LocalizedException ;
25
28
use Magento \Store \Model \Store ;
@@ -31,9 +34,11 @@ class CatalogCategoryAndProductResolverOnSingleStoreMode
31
34
{
32
35
/**
33
36
* @param ResourceConnection $resourceConnection
37
+ * @param MetadataPool $metadataPool
34
38
*/
35
39
public function __construct (
36
- private readonly ResourceConnection $ resourceConnection
40
+ private readonly ResourceConnection $ resourceConnection ,
41
+ private readonly MetadataPool $ metadataPool
37
42
) {
38
43
}
39
44
@@ -47,6 +52,8 @@ public function __construct(
47
52
*/
48
53
private function process (int $ storeId , string $ table ): void
49
54
{
55
+ $ productMetadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
56
+ $ productLinkField = $ productMetadata ->getLinkField ();
50
57
$ catalogProductTable = $ this ->resourceConnection ->getTableName ($ table );
51
58
52
59
$ catalogProducts = $ this ->getCatalogProducts ($ table , $ storeId );
@@ -56,8 +63,8 @@ private function process(int $storeId, string $table): void
56
63
try {
57
64
if ($ catalogProducts ) {
58
65
foreach ($ catalogProducts as $ catalogProduct ) {
59
- $ rowIds [] = $ catalogProduct [' row_id ' ];
60
- $ attributeIds [] = $ catalogProduct [' attribute_id ' ];
66
+ $ rowIds [] = $ catalogProduct [$ productLinkField ];
67
+ $ attributeIds [] = $ catalogProduct [AttributeInterface:: ATTRIBUTE_ID ];
61
68
$ valueIds [] = $ catalogProduct ['value_id ' ];
62
69
}
63
70
$ this ->massDelete ($ catalogProductTable , $ attributeIds , $ rowIds );
@@ -107,12 +114,12 @@ public function migrateCatalogCategoryAndProductTables(int $storeId): void
107
114
/**
108
115
* Delete default store related products
109
116
*
110
- * @param $catalogProductTable
117
+ * @param string $catalogProductTable
111
118
* @param array $attributeIds
112
119
* @param array $rowIds
113
120
* @return void
114
121
*/
115
- private function massDelete ($ catalogProductTable , array $ attributeIds , array $ rowIds ): void
122
+ private function massDelete (string $ catalogProductTable , array $ attributeIds , array $ rowIds ): void
116
123
{
117
124
$ connection = $ this ->resourceConnection ->getConnection ();
118
125
@@ -129,11 +136,11 @@ private function massDelete($catalogProductTable, array $attributeIds, array $ro
129
136
/**
130
137
* Update default store related products
131
138
*
132
- * @param $catalogProductTable
139
+ * @param string $catalogProductTable
133
140
* @param array $valueIds
134
141
* @return void
135
142
*/
136
- private function massUpdate ($ catalogProductTable , array $ valueIds ): void
143
+ private function massUpdate (string $ catalogProductTable , array $ valueIds ): void
137
144
{
138
145
$ connection = $ this ->resourceConnection ->getConnection ();
139
146
0 commit comments