experius / Magento2-Module-Experius-ReindexCatalogUrlRewrites

Adds a function to Magento 2 to fix or 'reindex' your catalog product urls rewrites with a console command line script
10 stars 2 forks source link

Update product url_path before reindexing url_rewrites #14

Open MatthijsBreed opened 4 years ago

MatthijsBreed commented 4 years ago

After changing a product's url_key, it is possible it's url_path is not changed. So if the experius_reindexcatalogurlrewrites:producturls command is ran the following data is used: ["entity_id"]=> string(4) "7038" ["attribute_set_id"]=> string(1) "4" ["type_id"]=> string(6) "simple" ["sku"]=> string(10) "460500-kit" ["has_options"]=> string(1) "0" ["required_options"]=> string(1) "0" ["created_at"]=> string(19) "2019-09-09 10:15:09" ["updated_at"]=> string(19) "2019-10-17 15:08:51" ["name"]=> string(29) "ADR bijrijderskit (verplicht)" ["url_key"]=> string(34) "adr-bijrijderskit-verplicht-460510" ["url_path"]=> string(38) "adr-bijrijderskit-verplicht-460500-kit" ["visibility"]=> string(1) "4" ["store_id"]=> string(1) "1" Since the url_path is used for generating the url-rewrites, this will result rewrites based on the old url_key.

Suggested fix: Regenerate a product's url_path before reindexing url_rewrites

MatthijsBreed commented 4 years ago

Core Magento Class that does this: vendor\magento\module-catalog-url-rewrite\Observer\ProductProcessUrlRewriteSavingObserver.php