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/zipwire/zipwire.nl/app/KommaApp/Shop/Categories/CategoryController.php
<?php

namespace App\KommaApp\Shop\Categories;

use App\Http\Controllers\Controller;
use App\KommaApp\Shop\Categories\Kms\CategoryService;
use App\KommaApp\Shop\Categories\Kms\CategoryServiceInterface;
use App\KommaApp\Shop\Categories\Models\Category;

class CategoryController extends Controller
{
    private $pagePrefix = 'shop.pages.categories.';
    private $categoryService;

    public function __construct(CategoryServiceInterface $categoryService)
    {
        parent::__construct();
        $this->categoryService = $categoryService;
    }

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function index()
    {
        $page = $this->pageService->getPageByCodeName('categories');
//        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);

//        $products = $this->categoryService->modelsWithoutGroups(); //All products that are not in groups or composites with their translation for the current language
//        $groups = $this->groupService->modelsNotInComposites(); //All groups that are not in composites with their translation for the current language
//        $composites = $this->compositeService->models(); //All composites

//        $categoryTree = $this->categoryService->getModelTree(\App::getSite()->id)->getTree();

        //TODO. Retrieving products like this is not the way to go. Thats why we are going to make a catalog thingy.

        // Return view
        return \View::make($this->pagePrefix.'index',[
            'page' => $page,
            'links' => $this->links,
//            'otherLanguages' => $otherLanguageRoutes,
//            'categoryTree' => $categoryTree,
        ]);
    }

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function filters()
    {
        $filters = request('filters');
        var_dump('Filter posts with these filters:');

        $page = $this->pageService->getPageByCodeName('categories');
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);

        $categoryTree = $this->categoryService->getModelTree(\App::getSite()->id)->getTree();

        // Return view
        return \View::make($this->pagePrefix.'index',[
            'page' => $page,
            'links' => $this->links,
            'otherLanguages' => $otherLanguageRoutes,
            'categoryTree' => $categoryTree,
        ]);
    }


    /**
     * @param Page $page
     * @return \Illuminate\Contracts\View\View
     */
    public function show(Category $categoryTranslation)
    {
        $categoryTranslation->load('translation', 'sites');

        // This checks if the post belongs to the set site
        if(! $categoryTranslation->sites->contains(\App::getSite())) throw abort(404);

        $page = $this->pageService->getPageByCodeName('categories');
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page, $categoryTranslation);

        $category = $this->service->getModel($categoryTranslation->category_id);
        $subCategories = $this->service->getModelsBetween($category->lft, $category->rgt, \App::getSite()->id);

        // Return view
        return \View::make($this->baseViewPath.$this->pagePrefix.'show',[
            'page' => $page,
            'category' => $category,
            'links' => $this->links,
            'otherLanguages' => $otherLanguageRoutes
        ]);
    }

}