Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note

Backend documentation in progress

Product Url Generator

vendor/creativestyle/magesuite-url-regeneration/Service/Product/UrlGenerator.php:46
Code Block
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
Code Block
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
Code Block
/**
 * Generates Product/Category URLs for different scopes
 */
class ProductScopeRewriteGenerator
{
    /**
     * Generate list of urls for specific store view
     */
    public function generateForSpecificStoreView($storeId, $productCategories, Product $product, $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()
        );
    }
}

Category Url Generator

vendor/creativestyle/magesuite-url-regeneration/Service/Category/UrlGenerator.php:39
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.

...