magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.48k stars 9.29k forks source link

CMS Page with identifier shipping cannot save. The value specified in the URL Key field would generate a URL that already exists #35115

Open aliomattux opened 2 years ago

aliomattux commented 2 years ago

Preconditions (*)

  1. 2.4.3-p1

Steps to reproduce (*)

  1. Go to Content > Pages
  2. Edit an existing CMS page with identifier shipping or create a new CMS page with identifier shipping
  3. Press Save

Expected result (*)

  1. The CMS page is saved without error.

Actual result (*)

  1. Error message is thrown preventing saving. The value specified in the URL Key field would generate a URL that already exists.

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

Description This bug report is linked to bug: https://github.com/magento/magento2/issues/31007 but is not the same issue.

It is easy to respond and say that Magento core has a frontName value of shipping and therefore, you cannot use ever the url key shipping.

In a rebuttal to such a general statement, shipping is one of the most popular and widely used urls. It is a url used by companies to explain shipping polciies. Several major websites worldwide use this url, and Magento is saying, you cannot use it.

This new validator did not exist in previous versions of Magento 2. In our case we have had since 2008 a url for /shipping. Now Magento decides to not allow it, that doesn't work. We are forced to override "woraround" the validator to update content to a page that cannot just be changed because Magento needs it.

m2-assistant[bot] commented 2 years ago

Hi @aliomattux. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 2 years ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Hotel commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Hotel. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Hotel, here is your Magento Instance: https://2c8a342c3915f819f9d770eb549093b3.instances.magento-community.engineering Admin access: https://2c8a342c3915f819f9d770eb549093b3.instances.magento-community.engineering/admin_ec37 Login: b9a88714 Password: d20993e15b96

engcom-Hotel commented 2 years ago

Hello @aliomattux,

Thanks for posting the issue!

We have tried to reproduce the issue in the fresh installed Magento 2.4-develop branch. But for us, the issue is not reproducible. We are able to save the CMS block successfully. Please have a look at the below screenshot for reference:

image

Let us know if we have missed anything.

Thanks

schnere commented 2 years ago

In my case I have to problem when I create a CMS page with URL key "newsletter". If I change the URL key to newsletter1 it works fine.

chardwick99 commented 2 years ago

@engcom-Hotel, I am having the issue with a CMS Page, with any duplicate URL for two different store's CMS Pages. This should not happen.

Preconditions 2.3.7p-2, MultiStore enabled

Steps to reproduce Go to Content > Pages Create two CMS pages with different store views, and identical URL identifiers (e.g. "home") Press Save

Expected result The CMS page is saved without error.

Actual result Error message is thrown preventing saving. "Could not save the page: URL key for specified store already exists."

m2-assistant[bot] commented 2 years ago

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-November commented 2 years ago

Verified the issue on Magento 2.4-develop branch and the issue is reproducible: Admin - Content - Pages - Add New page or Edit existing page with URL key: shipping and Save image

github-jira-sync-bot commented 2 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-2554 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 years ago

:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

pranav7870 commented 2 years ago

@magento I am working on this

pranav7870 commented 2 years ago

Hello @aliomattux i've try to reproduce issue in magento 2.4.3-p1. If you have cms page with url key like "shipping, cart, checkout" you will not be able to save it after migration because the validator of url key will find that there is frontend route "shipping, cart, checkout" defined from modules. if you want to remove this validator then remove line from

diff --git a/vendor/magento/module-cms/Model/PageRepository.php b/vendor/magento/module-cms/Model/PageRepository.php index e0f50bd..8881534 100644 --- a/vendor/magento/module-cms/Model/PageRepository.php +++ b/vendor/magento/module-cms/Model/PageRepository.php @@ -168,7 +168,7 @@ class PageRepository implements PageRepositoryInterface

}
try {
$this->validateLayoutUpdate($page);

   //$this->validateRoutesDuplication($page);
   $this->resource->save($page);
   $this->identityMap->add($page);
} catch (\Exception $exception) {

please check this and let me know if any issues. Thanks

chardwick99 commented 2 years ago

@pranav7870 Will this fix also fix the problem for ANY url key, not just "shipping, cart, checkout"? @engcom-November verified this as a bug further upthread. This happens when any CMS Page's url key matches another. (e.g "home", "distributors", "XYZ", etc.

pranav7870 commented 2 years ago

@pranav7870 Will this fix also fix the problem for ANY url key, not just "shipping, cart, checkout"? @engcom-November verified this as a bug further upthread. This happens when any CMS Page's url key matches another. (e.g "home", "distributors", "XYZ", etc.

Hello @chardwick99 i've fix this for all urls please check with my code, please check and let me know. Thanks

aliomattux commented 2 years ago

@pranav7870 I already know about the proposed "fix". This fix requires me to modify the core code. I reported this as a bug because of the industry standard use of the url key "shipping". As stated in my initial post, many popular ecommerce websites use the url. Additionally, Magento 2 has been operational for years and many ecommerce stores already make use of the url key shipping. Creating the requirement for customers to change the url IMO is a bug introduced. I do not expect it to be changed, but it should be. Therefore, I reject the proposal customers should have to modify their installation to bypass the issue.

bartoszkubicki commented 2 years ago

I have the same issue with route "klarna". After longer consideration that mechanism is not entirely bad, but should more accurate, for example these routes reserved by modules, are not fully occupied, for example 'klarna/index/index' is up for grabs.

plastikschnitzer commented 2 years ago

If certain page identifiers should be "reserved", their error message should be adapted and not direct in a direction of page identifier duplicates – which is also correct in some way but it won't help you finding the duplicate in your cms pages.

LaurensFranken commented 1 year ago

Getting the same issue but with url_key contact. Magento version 2.4.5-p2. There are no other CMS pages with the same url key, nor are there any redirects setup for that particular key. The option Add Store Code to Urls is configured to "No". This used to work in the previous version (Magento 2.3.5-p2).

image
kpitn commented 9 months ago

This error is not due to specicif key reserved.

To reproduce the bug you can do :

ex : you create a /faq page with all store
=> Magento generate all url_rewrite with all store

you want to create a page for /faq for a specific store
=> You have this error : "The value specified in the URL Key field would generate a URL that already exists."

Here is the patch to fix the bug :

--- Observer/ProcessUrlRewriteSavingObserver.php
+++ Observer/ProcessUrlRewriteSavingObserver.php
@@ -46,9 +46,15 @@

         if ($cmsPage->dataHasChangedFor('identifier')
             || $cmsPage->dataHasChangedFor('store_id')
-            || $cmsPage->getData('rewrites_update_force')
         ) {
             $urls = $this->cmsPageUrlRewriteGenerator->generate($cmsPage);
+
+            if ($cmsPage->getStoreId()) {
+                $this->urlPersist->deleteByData([
+                    UrlRewrite::REQUEST_PATH => $cmsPage->getIdentifier(),
+                    UrlRewrite::STORE_ID     => $cmsPage->getStoreId(),
+                ]);
+            }

             $this->urlPersist->deleteByData([
                 UrlRewrite::ENTITY_ID => $cmsPage->getId(),