code: private function validIdentity(Identity $categoryIdentity, CategoryModel $shopMainCategory)
      {
          try {
              $existingCategory = $this->categoryRepository->find($categoryIdentity->getAdapterIdentifier());
  
              if (null === $existingCategory) {
                  return false;
              }
  
              $extractedCategoryPath = array_filter(explode('|', $existingCategory->getPath()));
  
              if (in_array($shopMainCategory->getId(), $extractedCategoryPath)) {
                  return true;
              }
  
              return false;
          } catch (Exception $exception) {
              return false;
          }
      }
docs: @param Identity      $categoryIdentity
  @param CategoryModel $shopMainCategory
  
  @return bool