0

Magento is creating rewrite_urls for categories by their name so when the name is full UTF8 like تست or تت it produce empty string for url rewrite like this:

 .html

so it will insert duplicate url rewrites and this error return in rest call

{"message":"Could not save category: %1","parameters":["URL key for specified store already exists."],"trace":"#0 [internal function]: Magento\\Catalog\\Model\\CategoryRepository->save(Object(Magento\\Catalog\\Model\\Category\\Interceptor))\n#1 \/Users\/sinamiandashti\/projects\/magento\/vendor\/magento\/module-webapi\/Controller\/Rest.php(307): call_user_func_array(Array, Array)\n#2 \/Users\/sinamiandashti\/projects\/magento\/vendor\/magento\/module-webapi\/Controller\/Rest.php(216): Magento\\Webapi\\Controller\\Rest->processApiRequest()\n#3 \/Users\/sinamiandashti\/projects\/magento\/var\/generation\/Magento\/Webapi\/Controller\/Rest\/Interceptor.php(24): Magento\\Webapi\\Controller\\Rest->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#4 \/Users\/sinamiandashti\/projects\/magento\/vendor\/magento\/framework\/App\/Http.php(135): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#5 \/Users\/sinamiandashti\/projects\/magento\/vendor\/magento\/framework\/App\/Bootstrap.php(258): Magento\\Framework\\App\\Http->launch()\n#6 \/Users\/sinamiandashti\/projects\/magento\/pub\/index.php(37): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http))\n#7 {main}"}
0

Fixed by this data array

$data = array(
            "category" => array(
                "name" => $row['name'],
                "parent_id" => 2,
                "is_active" => true,
                'custom_attributes' => array(
                    array('attribute_code' => 'old_cat_id', 'value' => $row['id']),
                    array('attribute_code' => 'url_key', 'value' => $slug),
                ),
            ),

            "save_options" => true,

        );

please note that url_key in attributes

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.