protected function resolveCategoryIds($categoryId, $topLevel = false, $storeViewCode = StoreViewCodes::ADMIN)
    {

        // return immediately if this is the absolute root node
        if ((integer) $categoryId === 1) {
            return;
        }

        // load the data of the category with the passed ID
        $category = $this->getCategory($categoryId, $storeViewCode);

        // query whether or not the product has already been related
        if (!in_array($categoryId, $this->productCategoryIds)) {
            if ($topLevel) {
                // relate it, if the category is top level
                $this->productCategoryIds[] = $categoryId;
            } elseif ((integer) $category[MemberNames::IS_ANCHOR] === 1) {
                // also relate it, if the category is not top level, but has the anchor flag set
                $this->productCategoryIds[] = $categoryId;
            } else {
                $this->getSubject()
                     ->getSystemLogger()
                     ->debug(sprintf('Don\'t create URL rewrite for category "%s" because of missing anchor flag', $category[MemberNames::PATH]));
            }
        }

        // load the root category
        $rootCategory = $this->getRootCategory();

        // try to resolve the parent category IDs
        if ($rootCategory[MemberNames::ENTITY_ID] !== ($parentId = $category[MemberNames::PARENT_ID])) {
            $this->resolveCategoryIds($parentId, false);
        }
    }