Skip to content
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

Product URL rewrite is not removed when switching visibility #10725

Closed
kanduvisla opened this issue Aug 31, 2017 · 7 comments
Closed

Product URL rewrite is not removed when switching visibility #10725

kanduvisla opened this issue Aug 31, 2017 · 7 comments
Labels
bug report Component: CatalogUrlRewrite Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@kanduvisla
Copy link
Contributor

I know there are a lot of URL rewrite-related issues, but this one is very clear and reproducible.

Preconditions

  1. Magento 2.1.7

Steps to reproduce

  1. Create a product that is disabled and has visibilty set to 'not visible individually'
  2. Check the URL rewrite table. It should not have a URL rewrite (Magento creates those only for visible products).
  3. Edit the product, setting visibility to 'Category & Search'.
  4. Check the URL Rewrite table. A record has been added. So far so good.
  5. Edit the product, setting visibility back to 'Not visible individually'.
  6. Check the URL Rewrite table. The record still exists.
  7. Even if you enable or disable the non-visible product, the url_key in the url_rewrite table still exists.

Expected result

I expected the record to be deleted as soon as a product is set back to not visible (or even disabled). Because now, a new product that has the same url key cannot be saved. This is especially useful in a scenario where new products are imported (using Magento's repository/save method), and old products are disabled or made not visible in the process.

Actual result

The url_key remains in the url_rewrite table, making it impossible for future products to have the same url_key as a product that has been disabled or made invisible in the past.


I thought about if this is a bug or a feature because if it would be a feature, I would expect the url_key to be generated as well when I create a new, non-visible product. However, this is not the case. So either the url_key should be created always, or it should only be created when the status and/or visibility allow it (and it should be cleaned up if not).

@kanduvisla
Copy link
Contributor Author

I found the cause of the problem: when saving a product, the catalog_product_after_save event is caught by Magento\CatalogUrlRewrite\Observer\ProductProcessUrlRewriteSavingObserver::execute(). This class calls a deleteByData()-method that uses $product->getStoreId() as a condition to delete the already existing url_rewrite.

However, the rewrite is saved in the database table with store_id 1, and $product->getStoreId() will return 0 when the product is saved from the admin (when the admin is set to 'all store views').

@orlangur
Copy link
Contributor

Did you ever change single-store mode setting? Please extend description with this information then.

@kanduvisla
Copy link
Contributor Author

@orlangur: no, this is just a default installation. But I analyzed the code and the observer in question doesn't check for that configuration setting. It just asks the store ID from the product that is being saved, which is 0 for the admin/default store values, but the url rewrites are saved on a per-store base, so ID 0 is never used there.

@magento-engcom-team magento-engcom-team added G1 Passed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed bug report Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed G1 Passed labels Sep 5, 2017
@okorshenko okorshenko added the Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed label Sep 14, 2017
@psiwik
Copy link

psiwik commented Sep 17, 2017

i take it

psiwik pushed a commit to psiwik/magento2 that referenced this issue Sep 17, 2017
@ghost ghost added Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Component: CatalogUrlRewrite Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Sep 6, 2018
@ghost
Copy link

ghost commented Jan 23, 2019

Hi @kanduvisla i'm closing this one as we have new issue, -> #20434

@ghost ghost closed this as completed Jan 23, 2019
@sivaschenko sivaschenko reopened this Feb 13, 2019
@sivaschenko sivaschenko changed the title M2.1.7: Product URL rewrite is not being removed when a products' visibility is switched back to 'Not visible individually'. Product URL rewrite is not removed when switching visibility Feb 13, 2019
@magento-engcom-team
Copy link
Contributor

@kanduvisla, thank you for your report.

Unfortunately, we are archiving this ticket now as it did not get much attention from both Magento Community and Core developers for an extended period. This is done in an effort to create a quality, community-driven backlog which will allow us to allocate the required attention more easily.

Please feel free to comment, reopen or create new ticket according to the Issue reporting guidelines
if you are still facing this issue on the latest 2.4-develop branch. Thank you for collaboration.

@sheepfy
Copy link
Contributor

sheepfy commented Jun 7, 2021

4 years later, issue is still present

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: CatalogUrlRewrite Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

8 participants