-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Change URL Key behaviour to allow the same key to be used more then once #10356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Added function to generate URL based on URL Key and entity id. - Added behaviour which was present in Magento 1 where and URL key is checked before saving it.
- Fixed test, added mock to constructor
…generated because it conflicts with the canonical URL.
…ck for duplicates.
…L's already generated.
I don't agree with these proposed changes. Url keys's should be unique and should not be auto-generated when a duplicate is found, it should fail to save the product when something like that is detected. What does need to be improved:
Just my 2 cents :) |
@hostep Thank you for your suggestion, the error message can be much more clear then it currently is. However autogenerating the URL when the primary one is not availabe has been a feature in Magento 1. It's also works the same in Wordpress, the leading CMS / Blog platform worldwide. It has the same behaviour, no error when using the same page title twice, but appending the URL with a number automatically. So it's something users are expecting and are ready to deal with. It's upto the @magento-team to determine which way they want to move forward with the URL rewrites. In my opinion we should preserve the functionality offered by Magento 1, since users are accustomed to it and it makes migrating from M1 to M2 a lot easier. Above all it's common best practice in a number of top used e-commerce, cms and blog platforms worldwide. |
It's not because people are used to a certain behaviour, that it is a good one :) I just got to think about a possible case where your proposed logic could go wrong.
With your proposed solution, PRODUCT_B2's url key should automatically been changed to 'product-b-{someid}' Suppose a day later, you import the same products again, but in a different order:
Now what will happen? PRODUCT_B2's url key will change to 'product-b' and PRODUCT_B1's url key will change to 'product-b-{some-other-id}' This means that a product's url has changed without the shop owner knowing about it and previous url's linking to the original product will now end up somewhere else. This is the biggest issue I have with the proposed changes, that url's can change 'out of the blue' and that's a very bad idea (that was also a huge problem in Magento1 btw ;)) Anyway, this just popped into my head, haven't really thought it trough a lot, but I think it's very dangerous to let url key's be generated automatically should a duplicate be detected. |
@hostep, just because you personally don't feel like using this functionality - doesn't mean other people should be deprived from it, as well. |
@hostep @korostii I don't think the system itself should apply any restrictions. If you want to make sure that every product has a URL without the ID included it can be checked while doing the import. The changes in this PR will set the URL key once and it will only be changed if a category is moved or the URL key for the specified product is changed. It will also create redirects for the original URL's, so that they will be preserved. |
Looks like you didn't check changes introduced in scope of #6671 which improve URL Rewrites functionality in the right direction (available in I personally vote for I appreciate the efforts invested to embody your idea into life but generally it is better to conduct a technical discussion before doing any controversial changes, just to avoid waste of such efforts (recent example - whether we can validate emails by just presence of |
Hi @orlangur, No, I did not miss the changes in the commit you are referencing. I have created issue #10242 for this. It was designated a feature request by the @magento-team and @choukalos. So in order to get things up to speed I have created this PR to resolve this issue. The @magento-team can decide which way they want to go with the URL rewrites. But I'm suggesting that an URL key should no be unique, especially for the following reasons:
|
I don't think making such a crucial thing as a switch in core is a good idea. What if you want to switch it back at some point? It means starting work on any Magento 2 shop you'll have to check it first just to understand how system behaves. Implementation is not supplied with any tests, just removed few broken ones. Adding any feature to core means it will be fully maintained by core team later, preserving backward-compatibility and doing any required adoption with future features. So, I think such functionality should be better implemented as a third-party module. I wouldn't make it a switch in Admin UI, but making it an option in Setup seems a viable solution to me. |
@orlangur Unfortunately you did not check the description of this PR or the commit comments. The test where changed because in the Anchor rewrite generator I have removed the current Magento behaviour where it will generate URL's for the website root category. This is not necessary and should be removed. It will create duplicate entries in the url_rewrite table such as the URL "/product-name.html". So the total number of URL's being generated is less. We will wait in see how the @magento-team wants to go forward with this. However when so much users do not understand the way the system works. Is that the users or the systems fault? In my opinion it's the last and the system should take the users into account. So that's the reason for these proposed changes. |
… not caused by this PR, so only fixed new issues mentioned by Codacy.
What's wrong about that? Would you rather hunt down for custom code, 3rd-party modules or even patches to the core - whatever the previous maintainer might've used in order to reach the very same goal precisely because this feature is not provided out of the box? How is that any better? |
At least we can agree on that other point you make along the way:
However I'd like to see it work both ways, meaning I wish @magento-team would also announce any future (possibly controversial) changes before they implement them and put them into a release, so that the community could at least warn them about possible issues in advance. |
This "feature" is not provided out of the box simply because it is not needed out of the box. From my experience once you solved all problems in your invalid data after migration and having understanding how URL Rewrites are generated in Magento 2 the things go smoothly. Having some switches in core for such a crucial things makes predictability of system behavior quite low.
That's the point. There is no need to waste core team efforts to keep features needed only for those with poorly migrated data / misunderstanding of URL Rewrites behavior in Magento 2. Magento should promote best practices and not some hacky solutions bringing more surprises to developers than a real value. |
Clearly, people are struggling - numerous issues both her and on stackexchange speak about that loudly. You aren't denying that, are you?
I would continue to argue that it's less harmful (than forcing users to do core hacks themselves instead).
a) Initial code is provided by community in this case.
Last time I checked, developers aren't the only people using Magento. There are also the merchants. |
Oops, missed that one at first. You mean having it selected during Magento's initial installation and storing in |
@dverkade Can you please provide a patch for this PR ? |
This PR seems to inform us of how things work, but not how to fix it. I have a category giving me the URL key error. I tried to change the URL key, and unchecked creating a permanent redirect, and resave, and it still gave me the same error. If we are getting this error in a category, what is a quick fix for it? Do you have a step by step processes? Also I agree with @korostii , I'm not a developer using this site, there are lots of us here that used M1 that are suddenly faced with the task of having to learn way more than we ever needed to know previously, just to get M2 functional. |
@dverkade, thanks for your endeavor to improve Magento functionality as you see it! As noted previously the problem this PR aims to solve is already fixed in Proposed system behavior change was evaluated and not approved. Before introducing any controversial changes it is always a good idea to get it designed and described as Generally, system behaves normally in current implementation if your data is valid in the first place. If https://github.com/magento/data-migration-tool produces invalid data in some cases, it should be reported instead of hacking core to automatically "fix" invalid data. |
That's new. Could you please elaborate on that? Has that officially changed recently? |
Nothing has changed as far as I know. Difference between "I want ..." and "Here is the problem, here is the design, let's just do it" is the key. Some examples: 9582 10863 (not linking intentionally as our discussion is unrelated) |
The tickets you mention aren't a very good example as far as I'm concerned. This doesn't really help with putting new suggested improvements up for wide discussion and Magento's internal approval. |
https://github.com/magento/magento2/issues?q=is%3Aopen+is%3Aissue+label%3A"up+for+grabs" actually, some of them were proposed by Community members and then approved. As far as I understand current process, improvements should be discussed on Community Forums and onsite events and after that they may appear as |
Well, I count 4 issues like that over whole 2017 to date. Those are negligible.
IMHO That's all very shady and overcomplicated. |
The behaviour of the URL key is different in Magento 1 and Magento 2. This PR will fix this, so that users will not get the widley reported "URL key for specified store already exists" error message anymore.
Description
This PR makes it possible to use the same URL key for a product more then once. This is a real life scenario and occurs quite often when migrating from Magento 1 to Magento 2 with the data migration tool. This tool will dump the same data into Magento 2 and after importing this data, this will result in the "URL key for specified store already exists" when editing categories, moving categories, editing products, etc. because the same URL key is used more then once (which was possible in Magento 1).
This PR checks the URL key as entered by the user. When the URL key already exists it will append the product entity id to the URL. So you can have a product name "Acme" with the same URL key and ID 1 and a product called "Acme" with the same URL key and ID 2. For the product with ID one, the URL in the rewrite table will be "acme.html", for the second product it will be "acme-2.html".
Also removed adding URL rewrites for the root categories, resulting in a URL starting with /product-name, which could conflict with the canonical URL being generated. Since the are both basically the same URL's. Added a check while generating the Anchor Categories URL's to not generate it for any root categories.
This PR does not have the same behaviour as Magento 1 where every (configurable?) product saved added a new entry into the url_rewrite table with a new number at the end.
Fixed Issues
This PR fixes a lot of issues which are reported with the "URL key for specified store already exists" error. I have listed a couple below, but this is not limited to this list.
Manual testing scenarios