1919namespace Magento \Catalog \Model \ResourceModel ;
2020
2121use Exception ;
22+ use Magento \Catalog \Api \Data \ProductInterface ;
23+ use Magento \Eav \Api \Data \AttributeInterface ;
2224use Magento \Framework \App \ResourceConnection ;
25+ use Magento \Framework \EntityManager \MetadataPool ;
2326use Magento \Framework \Exception \CouldNotSaveException ;
2427use Magento \Framework \Exception \LocalizedException ;
2528use Magento \Store \Model \Store ;
@@ -31,9 +34,11 @@ class CatalogCategoryAndProductResolverOnSingleStoreMode
3134{
3235 /**
3336 * @param ResourceConnection $resourceConnection
37+ * @param MetadataPool $metadataPool
3438 */
3539 public function __construct (
36- private readonly ResourceConnection $ resourceConnection
40+ private readonly ResourceConnection $ resourceConnection ,
41+ private readonly MetadataPool $ metadataPool
3742 ) {
3843 }
3944
@@ -47,6 +52,8 @@ public function __construct(
4752 */
4853 private function process (int $ storeId , string $ table ): void
4954 {
55+ $ productMetadata = $ this ->metadataPool ->getMetadata (ProductInterface::class);
56+ $ productLinkField = $ productMetadata ->getLinkField ();
5057 $ catalogProductTable = $ this ->resourceConnection ->getTableName ($ table );
5158
5259 $ catalogProducts = $ this ->getCatalogProducts ($ table , $ storeId );
@@ -56,8 +63,8 @@ private function process(int $storeId, string $table): void
5663 try {
5764 if ($ catalogProducts ) {
5865 foreach ($ catalogProducts as $ catalogProduct ) {
59- $ rowIds [] = $ catalogProduct [' row_id ' ];
60- $ attributeIds [] = $ catalogProduct [' attribute_id ' ];
66+ $ rowIds [] = $ catalogProduct [$ productLinkField ];
67+ $ attributeIds [] = $ catalogProduct [AttributeInterface:: ATTRIBUTE_ID ];
6168 $ valueIds [] = $ catalogProduct ['value_id ' ];
6269 }
6370 $ this ->massDelete ($ catalogProductTable , $ attributeIds , $ rowIds );
@@ -107,12 +114,12 @@ public function migrateCatalogCategoryAndProductTables(int $storeId): void
107114 /**
108115 * Delete default store related products
109116 *
110- * @param $catalogProductTable
117+ * @param string $catalogProductTable
111118 * @param array $attributeIds
112119 * @param array $rowIds
113120 * @return void
114121 */
115- private function massDelete ($ catalogProductTable , array $ attributeIds , array $ rowIds ): void
122+ private function massDelete (string $ catalogProductTable , array $ attributeIds , array $ rowIds ): void
116123 {
117124 $ connection = $ this ->resourceConnection ->getConnection ();
118125
@@ -129,11 +136,11 @@ private function massDelete($catalogProductTable, array $attributeIds, array $ro
129136 /**
130137 * Update default store related products
131138 *
132- * @param $catalogProductTable
139+ * @param string $catalogProductTable
133140 * @param array $valueIds
134141 * @return void
135142 */
136- private function massUpdate ($ catalogProductTable , array $ valueIds ): void
143+ private function massUpdate (string $ catalogProductTable , array $ valueIds ): void
137144 {
138145 $ connection = $ this ->resourceConnection ->getConnection ();
139146
0 commit comments