...
Code Block |
---|
class UrlGenerator
{
public function regenerate($categoryId, $withSubcategories = false)
{
$stores = $this->storeManager->getStores(false);
foreach ($stores as $store) {
$this->deleteOldUrls($store, $categoryId, $withSubcategories);
}
foreach ($stores as $store) {
$this->regenerateStoreUrls($store, $categoryId, $withSubcategories);
}
}
protected function regenerateStoreUrls(\Magento\Store\Api\Data\StoreInterface $store, int $categoryId, bool $withSubcategories = false)
{
$category = $this->getCategoryByStore($categoryId, $store);
.....
$newUrls = $this->categoryUrlRewriteGenerator->generate($category);
try {
$this->urlPersist->replace($newUrls);
} catch (\Exception $e) {} //phpcs:ignore
.....
foreach ($category->getChildrenCategories() as $childCategory) {
$this->regenerateStoreUrls($store, $childCategory->getId(), true);
}
}
} |
vendor/magento/module-catalog-url-rewrite/Model/CategoryUrlRewriteGenerator.php:102
Code Block |
---|
class CategoryUrlRewriteGenerator
{
/**
* Generate list of urls.
*/
public function generate($category, $overrideStoreUrls = false, $rootCategoryId = null)
{
.....
$urls = $this->isGlobalScope($storeId)
? $this->generateForGlobalScope($category, $overrideStoreUrls, $rootCategoryId)
: $this->generateForSpecificStoreView($storeId, $category, $rootCategoryId);
return $urls;
}
} |
vendor/magento/module-catalog-url-rewrite/Model/CategoryUrlRewriteGenerator.php:102
Code Block |
---|
class CategoryUrlRewriteGenerator
{
/**
* Generate list of urls
*/
public function generate($category, $overrideStoreUrls = false, $rootCategoryId = null)
{
.....
$urls = $this->isGlobalScope($storeId)
? $this->generateForGlobalScope($category, $overrideStoreUrls, $rootCategoryId)
: $this->generateForSpecificStoreView($storeId, $category, $rootCategoryId);
return $urls;
}
/**
* Generate list of urls per store
*/
protected function generateForSpecificStoreView($storeId, Category $category = null, $rootCategoryId = null)
{
$mergeDataProvider = clone $this->mergeDataProviderPrototype;
.....
return $mergeDataProvider->getData();
}
}
|
vendor/magento/module-url-rewrite/Model/Storage/AbstractStorage.php:82
Code Block |
---|
abstract class AbstractStorage implements StorageInterface
{
public function replace(array $urls)
{
if (!$urls) {
return [];
}
return $this->doReplace($urls);
}
} |
vendor/magento/module-catalog-url-rewrite/Model/Category/Plugin/Storage.php:59
Code Block |
---|
class Storage
{
/**
* Save product/category urlRewrite association
*/
public function afterReplace(StorageInterface $object, array $result, array $urls)
{
$toSave = [];
foreach ($this->filterUrls($result) as $record) {
$metadata = $record->getMetadata();
$toSave[] = [
'url_rewrite_id' => $record->getUrlRewriteId(),
'category_id' => $metadata['category_id'],
'product_id' => $record->getEntityId(),
];
}
if (count($toSave) > 0) {
$this->productResource->saveMultiple($toSave);
}
return $result;
}
/**
* Filter urls
*/
protected function filterUrls(array $urls)
{
$filteredUrls = [];
.....
$existingUrls = $data ? $this->urlFinder->findAllByData($data) : [];
$mergeDataProviderForNewUrls = $this->mergeDataProviderFactory->create();
$mergeDataProviderForOldUrls = $this->mergeDataProviderFactory->create();
$mergeDataProviderForNewUrls->merge($filteredUrls);
$mergeDataProviderForOldUrls->merge($existingUrls);
return array_intersect_key(
$mergeDataProviderForOldUrls->getData(),
$mergeDataProviderForNewUrls->getData()
);
}
} |
Frontend
There are no frontend functionalities in this module.
...