HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/topswtwmobile.komma.pro/app/controllers/SearchController.php
<?php

use KommaApp\Shop\Search\SearchService;
use KommaApp\Shop\Checkout\Shipping\ShippingCostsRepository;

class SearchController extends \BaseController
{
    /**
     * @var SearchService
     */
    private $searchService;

    /**
     * @param SearchService $searchService
     */
    public function __construct(SearchService $searchService)
    {
        $this->searchService = $searchService;
    }

    public function showResult()
    {
        if (\Request::ajax() || \Request::has('ajax')) return $this->showJsonResult();

//        if(\Input::has('switch'))
//        {
//            if(\Input::get('switch') == 'language')
//                return \Redirect::to(\Shop::getPageService()->page('home')->route);
//        }

        $query = \Input::get('q');

        if (empty($query)) {
            return \View::make( viewPrefix() . 'pages.searchResults')
                ->with([
                    'bodyClasses' => 'search-results',]);
        }

        $productResults = $this->searchService->searchProducts($query);
        $categoryResults = $this->searchService->searchCategories($query);
        $pageResults = $this->searchService->searchPages($query);
        $topCategory = false;
        if (!empty($categoryResults['result']) && !empty($productResults['result'])) {
            $topCategory['result'] = $categoryResults['result'][0];
        }

        \Session::set('search_query', $query);

        //Set newsearch to null
        $relatedSearch = null;

        //Get relatedSearch (or null)
        $relatedSearch = $this->searchService->getRelatedSearchString($query);

        $query = strip_tags($query);

        $shippingCostsRepository = new ShippingCostsRepository();
        $shipping_costs = $shippingCostsRepository->getEntities();

        return \View::make( viewPrefix() . 'pages.searchResults')
            ->with([
                'bodyClasses' => 'search-results',
                'productResults' => $productResults,
                'categoryResults' => $categoryResults,
                'pageResults' => $pageResults,
                'topCategory' => $topCategory,
                'relatedSearch' => $relatedSearch,
                'query' => $query,
                'shippingCosts' => $shipping_costs
            ]);
    }

    public function showJsonResult()
    {
        $query = \Input::get('q');

        $productResults = $this->searchService->searchProducts($query, true, 5);
        $categoryResults = $this->searchService->searchCategories($query, true, true, 5);
        $pageResults = $this->searchService->searchPages($query, true, 5);

        // Todo: filter results

        return json_encode([
            'productsResults' => (array)$productResults,
            'categoriesResults' => (array)$categoryResults,
            'pagesResults' => (array)$pageResults
        ], JSON_PRETTY_PRINT);
    }
}