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

Question: Regenerate everything #48

Closed
amenk opened this issue Dec 9, 2021 · 14 comments
Closed

Question: Regenerate everything #48

amenk opened this issue Dec 9, 2021 · 14 comments

Comments

@amenk
Copy link
Contributor

amenk commented Dec 9, 2021

In which order do I have to execute commands to regenerate everything?

regenerate:category:url for all stores?
regenerate:category:path for all stores?
then regenerate:product:url for all stores?

Maybe we should add this to the readme?

@peterjaap
Copy link
Collaborator

peterjaap commented Dec 9, 2021

Unless you're running a very old Magento version (<=2.1), you don't need the path commands. See https://github.com/elgentos/regenerate-catalog-urls#whats-the-difference-between-url_key-and-url_path

Otherwise, first keys, then paths, because;

The url_path is generated by taking the url_key and adding the suffix

But make sure you have removed the paths if they're there, because Magento still uses them when they're present.

@amenk
Copy link
Contributor Author

amenk commented Dec 9, 2021

We are at 2.4.3 but I believe we have a lot of trash in the database from old version :-(

@amenk
Copy link
Contributor Author

amenk commented Dec 9, 2021

Ah, we can remove the paths? like from the EAV table?

@peterjaap
Copy link
Collaborator

Then I'd suggest cleaning up the database first. Garbage in is garbage out.

@peterjaap
Copy link
Collaborator

@amenk yes, see the faq

@amenk
Copy link
Contributor Author

amenk commented Dec 15, 2021

@peterjaap can you confirm, also the category's url_paths should be deleted?
Had this discussion with @hostep baldwin-agency/magento2-module-url-data-integrity-checker#14 (comment)

And on our staging where I deleted both, category's + product's url_path magento still seems to write them, but not all (after delete + rebuild I see 59 rows for

select * from catalog_category_entity_varchar WHERE attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'url_path' AND entity_type_id = 3);

while before we had 5623 rows

We did not spot other url problems though...
We have 1415 categories and 5 stores.

@hostep
Copy link
Contributor

hostep commented Dec 15, 2021

@amenk: Magento always writes the url_path for categories to the database, but never for products.

The url_path for a category consists of all the parent categories url_key's + its own url_key, all concatenated with a /.
The url_path for products was a left over from Magento 1 that for some reason didn't get removed in Magento 2 and when it's filled up will cause issues when you try to update the url_key of a product. So it's best to delete all of them.

Hope this makes it a bit more clear.

@peterjaap: maybe you should update the title What's the difference between url_key and url_path? to What's the difference between url_key and url_path for products? on the FAQ section of the README file? I believe it causes a bit confusion because @amenk seems to think it applies to category entities as well.
Also the section underneath Why are my category rewrites for a non-default storeview in the default storeview's language? is very incorrect in my opinion, you'd probably best delete it, don't you think?

@peterjaap
Copy link
Collaborator

@hostep so you're saying the url_path values are still used for categories? Apparently I decided otherwise when I wrote that README but I could indeed be very wrong. Do you have a code reference to see where/how it is used?

@hostep
Copy link
Contributor

hostep commented Dec 21, 2021

Yes exactly.

Code reference, hmm, this class sounds related probably: https://github.com/magento/magento2/blob/7996e89bc5420220eae5d8b755e6e0f839cbd94a/app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlPathGenerator.php

But the easiest way to tell is:

  • Setup a clean Magento
  • Using the backoffice: create one product and create one category
  • Inspect the catalog_product_entity_varchar and catalog_category_entity_varchar database tables
  • Notice that for the product, no entry was created for the url_path attribute, and for category an entry did get created

Also, don't forget that this very module has a command to regenerate url_path's for category's: bin/magento regenerate:category:path 😉

@peterjaap
Copy link
Collaborator

The fact that that command is there doesn't say anything because the bin/magento regenerate:product:path used to be there as well ;)

I updated the readme accordingly :) ed2ed37

@hostep
Copy link
Contributor

hostep commented Dec 24, 2021

Okay great, thanks! 🙂

@amenk
Copy link
Contributor Author

amenk commented Jan 7, 2022

For the record concerning my original question:

This does not fix all URLs:

regenerate:category:url for all stores?
regenerate:category:path for all stores?
regenerate:product:url for all stores?

This does:

regenerate:category:path for all stores
regenerate:category:url for all stores
regenerate:product:url for all stores

@hostep
Copy link
Contributor

hostep commented Jan 7, 2022

Exactly, always generate paths before url rewrites (for categories)!

A month or so ago, I ran into a strange case when I needed to execute regenerate:category:path multiple times (up to 3 times) until everything was fixed, unfortunately I didn't have time to look into it back then ...

@amenk
Copy link
Contributor Author

amenk commented Jan 7, 2022

Oh wow, so I am not sure if the run-again fixed it in my case or the new order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants