diff --git a/app/code/Magento/Catalog/Model/Category/Link/SaveHandler.php b/app/code/Magento/Catalog/Model/Category/Link/SaveHandler.php index 29a1ef60a43de..f22c6903a230c 100644 --- a/app/code/Magento/Catalog/Model/Category/Link/SaveHandler.php +++ b/app/code/Magento/Catalog/Model/Category/Link/SaveHandler.php @@ -119,7 +119,9 @@ private function mergeCategoryLinks($newCategoryPositions, $oldCategoryPositions if ($key === false) { $result[] = $newCategoryPosition; - } elseif ($oldCategoryPositions[$key]['position'] != $newCategoryPosition['position']) { + } elseif (isset($oldCategoryPositions[$key]) + && $oldCategoryPositions[$key]['position'] != $newCategoryPosition['position'] + ) { $result[] = $newCategoryPositions[$key]; unset($oldCategoryPositions[$key]); } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Category/Link/SaveHandlerTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Category/Link/SaveHandlerTest.php index 78db12be56b42..0b85ef38387fa 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Category/Link/SaveHandlerTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Category/Link/SaveHandlerTest.php @@ -197,6 +197,21 @@ public function getCategoryDataProvider() ], [], //affected category_ids ], + [ + [3], //model category_ids + [ + ['category_id' => 3, 'position' => 20], + ['category_id' => 4, 'position' => 30], + ], // dto category links + [ + ['category_id' => 3, 'position' => 10], + ], + [ + ['category_id' => 3, 'position' => 20], + ['category_id' => 4, 'position' => 30], + ], + [3, 4], //affected category_ids + ], ]; }