UrlRegeneration
https://github.com/magesuite/url-regeneration
This module adds an option for regenerating selected or all product URLs at once and for regenerating a given category URL or all category URLs at once.
- 1 Installation
- 2 Admin settings
- 3 Backend
- 3.1 Product Url Generator
- 3.1.1 vendor/creativestyle/magesuite-url-regeneration/Service/Product/UrlGenerator.php:46
- 3.1.2 vendor/magento/module-catalog-url-rewrite/Model/ProductUrlRewriteGenerator.php:128
- 3.1.3 vendor/magento/module-catalog-url-rewrite/Model/ProductScopeRewriteGenerator.php:187
- 3.1.4 vendor/magento/module-url-rewrite/Model/Storage/AbstractStorage.php:82
- 3.1.5 vendor/magento/module-catalog-url-rewrite/Model/Category/Plugin/Storage.php:59
- 3.2 Category Url Generator
- 3.2.1 vendor/creativestyle/magesuite-url-regeneration/Service/Category/UrlGenerator.php:39
- 3.2.2 vendor/magento/module-catalog-url-rewrite/Model/CategoryUrlRewriteGenerator.php:102
- 3.2.3 vendor/magento/module-catalog-url-rewrite/Model/CategoryUrlRewriteGenerator.php:102
- 3.2.4 vendor/magento/module-url-rewrite/Model/Storage/AbstractStorage.php:82
- 3.2.5 vendor/magento/module-catalog-url-rewrite/Model/Category/Plugin/Storage.php:59
- 3.1 Product Url Generator
- 4 Frontend
Installation
This module is part of MageSuite metapackage
Installation if metapackage is not used:
composer require "creativestyle/magesuite-url-regeneration" ^1.0.0
Admin settings
Product URLs can be regenerated from the product listing page in the admin panel:
Remember that all old URLs related to selected products (including 301 redirects) will be removed. This operation may take some time depending on amount of products selected.
Category URLs can be regenerated from any category edit page:
Backend
Backend documentation in progress
Product Url Generator
vendor/creativestyle/magesuite-url-regeneration/Service/Product/UrlGenerator.php:46
class UrlGenerator
{
public function regenerate($productIds = [])
{
$stores = $this->storeManager->getStores(false);
foreach ($stores as $store) {
$this->regenerateStoreUrls($store, $productIds);
}
}
protected function regenerateStoreUrls($store, $productIds = [])
{
.....
$products = $collection->load();
foreach ($products as $product) {
$product->setStoreId($storeId);
$this->urlPersist->deleteByData([
\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::ENTITY_ID => $product->getId(),
\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::ENTITY_TYPE => \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE,
\Magento\UrlRewrite\Service\V1\Data\UrlRewrite::STORE_ID => $storeId
]);
$newUrls = $this->productUrlRewriteGenerator->generate($product);
try {
$this->urlPersist->replace($newUrls);
} catch (\Exception $e) {} //phpcs:ignore
}
}
}
vendor/magento/module-catalog-url-rewrite/Model/ProductUrlRewriteGenerator.php:128
class ProductUrlRewriteGenerator
{
/** Generate product url rewrites */
public function generate(Product $product, $rootCategoryId = null)
{
.....
$urls = $this->isGlobalScope($storeId)
? $this->generateForGlobalScope($productCategories, $product, $rootCategoryId)
: $this->generateForSpecificStoreView($storeId, $productCategories, $product, $rootCategoryId);
return $urls;
}
protected function generateForSpecificStoreView(
.....
) {
return $this->getProductScopeRewriteGenerator()
->generateForSpecificStoreView($storeId, $productCategories, $product, $rootCategoryId);
}
}
vendor/magento/module-catalog-url-rewrite/Model/ProductScopeRewriteGenerator.php:187
vendor/magento/module-url-rewrite/Model/Storage/AbstractStorage.php:82
vendor/magento/module-catalog-url-rewrite/Model/Category/Plugin/Storage.php:59
Category Url Generator
vendor/creativestyle/magesuite-url-regeneration/Service/Category/UrlGenerator.php:39
vendor/magento/module-catalog-url-rewrite/Model/CategoryUrlRewriteGenerator.php:102
vendor/magento/module-catalog-url-rewrite/Model/CategoryUrlRewriteGenerator.php:102
vendor/magento/module-url-rewrite/Model/Storage/AbstractStorage.php:82
vendor/magento/module-catalog-url-rewrite/Model/Category/Plugin/Storage.php:59
Frontend
There are no frontend functionalities in this module.