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/Cnc/SearchAutocomplete/Index/Magento/Catalog/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/app/code/Cnc/SearchAutocomplete/Index/Magento/Catalog/CategoryProduct.php.bak
<?php
/**
 * Copyright (c) 2019 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * cnc_searchautocomplete_m2
 * <[email protected]>
 */

declare(strict_types=1);

namespace Cnc\SearchAutocomplete\Index\Magento\Catalog;

use Cnc\Catalog\Model\Config;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\UrlFactory;
use Magento\Search\Helper\Data as SearchHelper;
use Magento\Store\Model\StoreManagerInterface;
use Mirasvit\SearchAutocomplete\Api\Service\CategoryProductInterface;
use Mirasvit\SearchAutocomplete\Index\Magento\Catalog\CategoryProduct as OriginalCategoryProduct;

class CategoryProduct extends OriginalCategoryProduct
{
    /**
     * @var StoreManagerInterface
     */
    private $storeManager;
    /**
     * @var CategoryRepositoryInterface
     */
    private $categoryRepository;
    /**
     * @var CategoryRepositoryInterface
     */
    private $searchHelper;

    public function __construct(
        StoreManagerInterface $storeManager,
        CategoryRepositoryInterface $categoryRepository,
        SearchHelper $searchHelper,
        UrlFactory $urlFactory,
        CategoryProductInterface $categoryProduct
    ) {
        parent::__construct(
            $storeManager,
            $categoryRepository,
            $searchHelper,
            $urlFactory,
            $categoryProduct
        );

        $this->storeManager = $storeManager;
        $this->categoryRepository = $categoryRepository;
        $this->searchHelper = $searchHelper;
    }

    /**
     * @return array
     * @throws NoSuchEntityException
     */
    public function getItems(): array
    {
        $items = [];
        $collection = $this->categoryProduct->getCollection($this->index);

        $store = $this->storeManager->getStore();
        $rootId = $store->getRootCategoryId();

        foreach ($collection as $category) {
            $url = $this->urlFactory->create()
                ->setQueryParam('q', $this->searchHelper->getEscapedQueryText())
                ->setQueryParam('cat', $category->getId())
                ->getUrl('catalogsearch/result');

            // @override START
            $iconCssClass = $category->getData(Config::CATEGORY_ATTRIBUTE_CODE_ICON_CSS_CLASS);

            $items[] = [
                'name' => $this->getFullPath($category, $rootId),
                'url' => $url,
                'icon_css_class' => $iconCssClass,
            ];
            // @override END

            if (count($items) >= $this->index->getLimit()) {
                break;
            }
        }

        return $items;
    }
}

Spamworldpro Mini