1

my code to create a category is the following:

private function createCategory($name='',$parentId=2,$active=true,$description='',$metaTitle='',$metaKeywords='',$metaDescription='') 
{
    if(!isset($metaTitle))
    {
        $metaTitle = $name;
    }
    $categoryRepository = $this->categoryRepository;
    $category = $this->categoryFactory->create();
    $category->setName($name);
    $category->setParentId($parentId);
    $category->setIsActive($active);
    $category->setCustomAttributes([
        'description' => $description,
        'meta_title' => $metaTitle,
        'meta_keywords' => $metaKeywords,
        'meta_description' => $metaDescription,
    ]);
    $category->save();

    $categoryRepository->save($category);

    return $category->getId();

}

this error came up: [Magento\Framework\Exception\AlreadyExistsException]

URL Key for specified store already exists

Any solution for this?

Can't expect this to happen when importing data.

PD: Thanks for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.