@@ -52,22 +52,22 @@ public function __construct(
52
52
*/
53
53
private function process (int $ storeId , string $ table ): void
54
54
{
55
- $ productMetadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
56
- $ productLinkField = $ productMetadata ->getLinkField ();
55
+ $ metadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
56
+ $ linkField = $ metadata ->getLinkField ();
57
57
$ catalogProductTable = $ this ->resourceConnection ->getTableName ($ table );
58
58
59
- $ catalogProducts = $ this ->getCatalogProducts ($ table , $ storeId );
60
- $ rowIds = [];
59
+ $ catalogProducts = $ this ->getCatalogProducts ($ table , $ linkField , $ storeId );
60
+ $ linkFieldIds = [];
61
61
$ attributeIds = [];
62
62
$ valueIds = [];
63
63
try {
64
64
if ($ catalogProducts ) {
65
65
foreach ($ catalogProducts as $ catalogProduct ) {
66
- $ rowIds [] = $ catalogProduct [$ productLinkField ];
66
+ $ linkFieldIds [] = $ catalogProduct [$ linkField ];
67
67
$ attributeIds [] = $ catalogProduct [AttributeInterface::ATTRIBUTE_ID ];
68
68
$ valueIds [] = $ catalogProduct ['value_id ' ];
69
69
}
70
- $ this ->massDelete ($ catalogProductTable , $ attributeIds , $ rowIds );
70
+ $ this ->massDelete ($ catalogProductTable , $ linkField , $ attributeIds , $ linkFieldIds );
71
71
$ this ->massUpdate ($ catalogProductTable , $ valueIds );
72
72
}
73
73
} catch (LocalizedException $ e ) {
@@ -115,20 +115,21 @@ public function migrateCatalogCategoryAndProductTables(int $storeId): void
115
115
* Delete default store related products
116
116
*
117
117
* @param string $catalogProductTable
118
+ * @param string $linkField
118
119
* @param array $attributeIds
119
- * @param array $rowIds
120
+ * @param array $linkFieldIds
120
121
* @return void
121
122
*/
122
- private function massDelete (string $ catalogProductTable , array $ attributeIds , array $ rowIds ): void
123
+ private function massDelete (string $ catalogProductTable , string $ linkField , array $ attributeIds , array $ linkFieldIds ): void
123
124
{
124
125
$ connection = $ this ->resourceConnection ->getConnection ();
125
126
126
127
$ connection ->delete (
127
128
$ catalogProductTable ,
128
129
[
129
130
'store_id = ? ' => Store::DEFAULT_STORE_ID ,
130
- ' attribute_id IN(?) ' => $ attributeIds ,
131
- ' row_id IN(?) ' => $ rowIds
131
+ AttributeInterface:: ATTRIBUTE_ID . ' IN(?) ' => $ attributeIds ,
132
+ $ linkField . ' IN(?) ' => $ linkFieldIds
132
133
]
133
134
);
134
135
}
@@ -155,15 +156,16 @@ private function massUpdate(string $catalogProductTable, array $valueIds): void
155
156
* Get list of products
156
157
*
157
158
* @param string $table
159
+ * @param string $linkField
158
160
* @param int $storeId
159
161
* @return array
160
162
*/
161
- private function getCatalogProducts (string $ table , int $ storeId ): array
163
+ private function getCatalogProducts (string $ table , string $ linkField , int $ storeId ): array
162
164
{
163
165
$ connection = $ this ->resourceConnection ->getConnection ();
164
166
$ catalogProductTable = $ this ->resourceConnection ->getTableName ($ table );
165
167
$ select = $ connection ->select ()
166
- ->from ($ catalogProductTable , ['value_id ' , ' attribute_id ' , ' row_id ' ])
168
+ ->from ($ catalogProductTable , ['value_id ' , AttributeInterface:: ATTRIBUTE_ID , $ linkField ])
167
169
->where ('store_id = ? ' , $ storeId );
168
170
return $ connection ->fetchAll ($ select );
169
171
}
0 commit comments