diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Category.php b/vendor/magento/module-catalog/Model/ResourceModel/Category.php index f56fecb8dc5..fed2acc54df 100644 --- a/vendor/magento/module-catalog/Model/ResourceModel/Category.php +++ b/vendor/magento/module-catalog/Model/ResourceModel/Category.php @@ -1,7 +1,7 @@ getId(); + $newParentId = $object->getParentId(); + if ($parentPath = $this->getCategoryPathById($newParentId)) { + $parentPathIds = explode("/", $parentPath); + } else { + $parentPathIds = []; + } + + if ($currentId && !empty($parentPathIds) && in_array($currentId, $parentPathIds)) { + throw new LocalizedException( + __('A category cannot be assigned to one of its own descendants.') + ); + } + + return $errors; + } + /** * Process positions of old parent category children and new parent category children. * diff --git a/vendor/magento/module-catalog/i18n/en_US.csv b/vendor/magento/module-catalog/i18n/en_US.csv index b9fdf6b4324..3aca0d24d9c 100644 --- a/vendor/magento/module-catalog/i18n/en_US.csv +++ b/vendor/magento/module-catalog/i18n/en_US.csv @@ -822,3 +822,4 @@ Details,Details "The url has invalid characters. Please correct and try again.","The url has invalid characters. Please correct and try again." "Restricted admin is allowed to perform actions with images or videos, only when the admin has rights to all websites which the product is assigned to.","Restricted admin is allowed to perform actions with images or videos, only when the admin has rights to all websites which the product is assigned to." "Synchronize website specific attributes values","Synchronize website specific attributes values" +"A category cannot be assigned to one of its own descendants.","A category cannot be assigned to one of its own descendants."