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/BrandController.php
<?php

use KommaApp\Shop\Categories\CategoryService;
use KommaApp\Shop\Menus\SidebarMenu;
use KommaApp\Shop\Tree\Tree;
use KommaApp\Shop\Modules\Modules;
use KommaApp\Shop\Submenu;


class BrandController extends BaseController
{
    /**
     * @var CategoryService
     */
    protected $categoryService;

    /**
     * @var Tree
     */
    protected $tree;
    /**
     * @var SidebarMenu
     */
    private $sidebarMenu;


    /**
     * @param CategoryService $categoryService
     * @param Tree $tree
     * @param SidebarMenu $sidebarMenu
     */
    public function __construct(CategoryService $categoryService,Tree $tree, SidebarMenu $sidebarMenu)
    {
        $this->categoryService = $categoryService;
        $this->tree = $tree;
        $this->sidebarMenu = $sidebarMenu;
    }

    /**
     * @return mixed
     */
    public function index()
    {
        // Get category id
        $categoryId = $this->routeData->routable->category_id;

        // Brand index page
        if($this->routeData->routable_type == 'Komma\Kms\Pages\Models\PageTranslation')
        {
            return $this->showAllBrands();
        }

        // Brand detail
        if($treeNode = $this->categoryService->getNodeById($categoryId))
        {
            // Return sub page
            if( ! empty($treeNode->children ))
            {
                return $this->shoWbrandDetail($categoryId);
            }

            // Check if we need to show brand, default false
            $showBrandInfo = false;
            //If it is the highest ellement, always show brand info
            if(!$treeNode->getParent()) $showBrandInfo = true;
            //Else if the description is not empty, show brand info
            elseif(!empty($treeNode->description))  $showBrandInfo = true;

            return \App::make('productController')->showAllProductsInCategory($treeNode,$showBrandInfo);
        }

        return App::abort(404);
    }

    /**
     * @return mixed
     */
    protected function showAllBrands() 
    {
        $treeNodes = $this->categoryService->getTreeNodes(false);
        $letters = $this->categoryService->getFirstLetters(true);
        // Return the view

        return View::make(viewPrefix() . 'pages.brands')
            ->withBrands($treeNodes)
            ->withLetters($letters);
    }

    /**
     * @param $categoryId
     * @return mixed
     */
    protected function showBrandDetail($categoryId)
    {
        $brand = $this->categoryService->getNodeById($categoryId);
        $mainBrand = $this->categoryService->getRootNode($brand);
        $sidebarMenu = $this->sidebarMenu->create($mainBrand);

        $brandHasParent = false;
        if(isset($brand->parent)) $brandHasParent = true;

        // Return the view
        return View::make( viewPrefix() .'pages.brandDetail')
            ->with([
                'entity' => $brand,
                'mainBrand' => $mainBrand,
                'menu' => $sidebarMenu,
                'brandHasParent' => $brandHasParent 
            ]);
    }
}