Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Soon/UrlIndexer/Model/Indexer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Soon/UrlIndexer/Model/Indexer/Category.php
<?php
/**
 * @license http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 * @author Hervé Guétin <[email protected]> <@herveguetin>
 * @copyright Copyright (c) 2017 Agence Soon (http://www.agence-soon.fr)
 */

namespace Soon\UrlIndexer\Model\Indexer;

class Category implements IndexerInterface
{
    /**
     * @var \Magento\Catalog\Model\CategoryFactory
     */
    private $categoryFactory;
    /**
     * @var \Magento\Store\Api\StoreRepositoryInterface
     */
    private $storeRepository;
    /**
     * @var \Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator
     */
    private $categoryUrlRewriteGenerator;
    /**
     * @var \Magento\UrlRewrite\Model\UrlPersistInterface
     */
    private $urlPersist;

    /**
     * Category constructor.
     * @param \Magento\Catalog\Model\CategoryFactory $categoryFactory
     * @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
     * @param \Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator
     * @param \Magento\UrlRewrite\Model\UrlPersistInterface $urlPersist
     */
    public function __construct(
        \Magento\Catalog\Model\CategoryFactory $categoryFactory,
        \Magento\Store\Api\StoreRepositoryInterface $storeRepository,
        \Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator $categoryUrlRewriteGenerator,
        \Magento\UrlRewrite\Model\UrlPersistInterface $urlPersist
    )
    {
        $this->categoryFactory = $categoryFactory;
        $this->storeRepository = $storeRepository;
        $this->categoryUrlRewriteGenerator = $categoryUrlRewriteGenerator;
        $this->urlPersist = $urlPersist;
    }

    public function reindex()
    {
        // Load root category (Id 1)
        /** @var \Magento\Catalog\Model\Category $category */
        $category = $this->categoryFactory->create();
        $category->getResource()->load($category, \Magento\Catalog\Model\Category::TREE_ROOT_ID);

        // Set its 'store_ids' data with all store IDs in order to generate URL rewrites for all stores
        $category->setData('store_ids', array_map(function (\Magento\Store\Api\Data\StoreInterface $store) {
            return $store->getId();
        }, $this->storeRepository->getList()));

        // We set the category store ID to 0 to force $this->categoryUrlRewriteGenerator
        // to generate URL rewrites for all stores
        $category->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
        $rawUrlRewrites[] = $this->categoryUrlRewriteGenerator->generate($category);

        // We remove URL rewrites that start with '.'
        // Those are the ones without a url key (level 1 categories)
        $urlRewrites = array_filter(reset($rawUrlRewrites), function (\Magento\UrlRewrite\Service\V1\Data\UrlRewrite $url) {
            if (strpos($url->getRequestPath(), '.') !== 0) {
                return $url;
            }
        });

        $this->urlPersist->replace($urlRewrites);
    }
}

Spamworldpro Mini