Call this script
BEARER=`n98-magerun2 admin:token:create admin` # or get a bearer via API
BASEURL="http://put-your-magento-base-url-here"
echo '{"category":{"name":"Test","is_active":1,"parentId":2}}' > /tmp/datacreate.json
curl -k -X POST $BASEURL/rest/V1/categories -H 'Content-Type: application/json' -H
"Authorization: Bearer $BEARER" -d @/tmp/datacreate.json > /tmp/result.json
Followup issue of #28197
Push the category again on store view level, and with the custom_attribute url_key set
EDIT
But this works only, if the url key is different. In case of Austria and German those are in almost every case the same (both use German) so there is no workaround
Hi @amenk. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:
@magento give me 2.4-develop instance - upcoming 2.4.x release
For more details, please, review the Magento Contributor Assistant documentation.
Please, add a comment to assign the issue: @magento I am working on this
I was able to reproduce it on 2.4-develop
Is this intended behavior or a bug?
I would say it's a bug because I get a empty URL when trying to get the category URL in a Block with the code:
{{widget type="Magento\Catalog\Block\Category\Widget\Link" template="category/widget/link/link_href.phtml" id_path="category/79"}}.
I get the category url for the first store view that have a different URL key and an entry in URL rewrite. But the exact same code doesn't works in the second store that have the exact same url key as the "All Store View" and that DOESN'T have an entry in URL rewrite.
I'm running Magento 2.3.4-p2, I haven't tried with 2.3.5 or 2.4-develop.
This may be a regression. I have 2 Magento installations running on 2 different servers. I've used pretty much the same script on both servers to create categories with the REST API. I've ran the script on the first server somewhere in 2019 on Magento 2.3.2 or 2.3.3. The categories url rewrites exists for both store views. On the second server, I've ran the script in March 2020 on Magento 2.3.4, the categories URL rewrites exists ONLY for the first store view. The first store view uses different URL key than "All Store View".
My workaround that fixed the issue is to append the store id to the url key. There is also an workaround suggestion, which I haven't tried, around the end of #16134.
@fgagne thanks for the confirmation. We already know about the URL regeneration script, but it's still really annoying as new categories are created in the PIM all the time, causing API pushes and URL problems.
Can you elaborate on your first workaround to append the store id?
@fgagne
Can you elaborate on your first workaround to append the store id?
do you mean pushing the same URL key with for example -2 appended to the second store? If so, yes this would work. But of course the visible URLs are then "not clean" anymore and have an unnecessary suffix
@amenk this is exactly what I've done.
But perhaps it could done the other way around?
Please keep us updated if you try it out.
@fgagne Okay, got it. That would work, but need changes in the API consumer. We'll try to identify the issue during the next days...
We try to make a failing test case.
Approach:
Extend or Copy \Magento\Catalog\Api\CategoryRepositoryTest::testCreate plus this fixture
dev/tests/integration/testsuite/Magento/Store/_files/core_second_third_fixturestore.php
@magento I am working on this
TL;DR when using /rest/V1/categories the first store is assumed; when using /rest/all/V1/categories instead it works
with @DanieliMi we found out that in In
https://github.com/magento/magento2/blob/a94aa0089a4385e21f33db4b684dc209efb08d51/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGenerator.php#L103 the store ID is 1, when pushing via API. When using the Admin backend it's 0 (global) and all URL keys are generated.
Workarkound is to push to /rest/all/V1/categories
Failing test case is here: https://github.com/DanieliMi/magento2/commit/9f2fa5b9fed3a9ed317ac39adf7619839ba0f667
Now the big question is if the API should behave like this or not.
Seems to me that creating a category should always create the url rewrites for all store views, whether "all" store code is passed or not. It seems Magento assume the url rewrite are created for all store views because when updating a store view with /rest/STORE_CODE/V1/categories/ with the same url key, no url rewrite is created.
In fact, updating a category should always check if the url rewrite is present and if not present create the url rewrite, whether the url key changed or not. Currently it seems the url rewrite part is skipped if the url key ain't modified.
Wondering what happens if someone creates a Category in the backend, while a specific Store-View is selected in the drop down?
Most helpful comment
Seems to me that creating a category should always create the url rewrites for all store views, whether "all" store code is passed or not. It seems Magento assume the url rewrite are created for all store views because when updating a store view with /rest/STORE_CODE/V1/categories/ with the same url key, no url rewrite is created.
In fact, updating a category should always check if the url rewrite is present and if not present create the url rewrite, whether the url key changed or not. Currently it seems the url rewrite part is skipped if the url key ain't modified.