olegkoval / magento2-regenerate_url_rewrites

Magento 2 extension which add feature of regenerating a url rewrites of products/categories
Academic Free License v3.0
430 stars 118 forks source link

Duplicate error on multi-store sites with same category trees #109

Closed nige-one closed 4 years ago

nige-one commented 5 years ago

I found a bug when regenerating URLs on a multi-store instance. In https://github.com/olegkoval/magento2-regenerate_url_rewrites/blob/8bc3974be85bc6cb6d44002f41810a986f9e9045/Console/Command/RegenerateUrlRewritesCategoryAbstract.php#L187 you build a query to avoid problematic ->setStoreId (didn't test that). On multi-site setups this leads to a multi-row result, while the following https://github.com/olegkoval/magento2-regenerate_url_rewrites/blob/8bc3974be85bc6cb6d44002f41810a986f9e9045/Console/Command/RegenerateUrlRewritesCategoryAbstract.php#L189 will only return the first found entry. This means that url rewrites can already exist if two stores belong to the same website.

By changing this from https://github.com/olegkoval/magento2-regenerate_url_rewrites/blob/8bc3974be85bc6cb6d44002f41810a986f9e9045/Console/Command/RegenerateUrlRewritesCategoryAbstract.php#L187

to

$sql = "SELECT t1.root_category_id FROM {$tableName1} t1 INNER JOIN {$tableName2} t2 ON t2.group_id = t1.group_id WHERE t2.store_id = {$storeId};";

it works fine.

Thanks for your great module!

nige-one commented 5 years ago

I made a PR https://github.com/olegkoval/magento2-regenerate_url_rewrites/pull/110

olegkoval commented 4 years ago

@nige-one Thank you for the pull request! Merged.

Best regards, Oleg Koval