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/hem-mechatronics.komma.pro/app/Komma/Products/ProductController.php
<?php

namespace App\Komma\Products;

use App\Komma\Base\Controller;
use App\Komma\Buttons\Models\Button;
use App\Komma\Buttons\Models\ButtonTranslation;
use App\Komma\Components\ComponentService;
use App\Komma\Pages\Models\Page;
use App\Komma\Products\Models\Product;
use App\Komma\Servicepoints\Models\Servicepoint;

class ProductController extends Controller
{
    private $productService;

    public function __construct(ProductService $productService)
    {
        parent::__construct();
        $this->productService = $productService;
    }

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function index()
    {
        $page = $this->links->products->node;

        // Make language menu for given page
        $languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);

        $products = $this->productService->getAllProducts(true);
        $products->withPath('/' . $this->links->products->route);

        $componentService = app(ComponentService::class);
        $components = $componentService->getViewComponents($page->translation);

        $this->pageService->setSharebleVariables($page->servicepoint_id, $page->cta_button_id, $page->cta_heading);

        // Return view
        return view('site.templates.products_index',[
            'page' => $page,
            'components' => $components,
            'products' => $products,
            'links' => $this->links,
            'languageMenu' => $languageMenu,
        ]);
    }

    /**
     * @param Product $service
     * @return \Illuminate\Contracts\View\View
     */
    public function show(Product $product)
    {
        $product->load('translation','translations', 'sites');
        // This checks if the product belongs to the set site
        if(! $product->site == $this->site) throw abort(404);

        $products = $this->productService->getAllProducts();

        $page = $this->links->products->node;
        // Make language menu for given page
        $languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);

        $componentService = app(ComponentService::class);
        $components = $componentService->getViewComponents($product->translation);

        // split the Hero images from the "normal" post images
        list($documents, $heroDocuments) = $product->translation->documents->partition(function ($document) {
            return $document->key == 'Documents-products';
        });
        $product->documents = $documents;

        // fill the page hero object
        $heroButton = Button::where('id', $product->translation->hero_button_id)->with('translation')->first();

        $product->hero = (object)[
            'documents' => $heroDocuments,
            'active' => $product->translation->hero_active,
            'title' => $product->translation->hero_title,
            'description' => $product->translation->hero_description,
            'buttons' => !empty($heroButton) ? $heroButton : null,
        ];

        $discover_more_page_codenames = $page->discoverPages()->get()->map(function(Page $page) {
            return $page->code_name;
        })->toArray();

        $showServicePoint = Servicepoint::find( !empty($product->servicepoint_id) ? $product->servicepoint_id : config('site.global_CTA_servicepoint_id'));

        $viewData = [
            'showServicePoint' => $showServicePoint,
            'page' => $page,
            'components' => $components,
            'products' => $products,
            'product' => $product,
            'links' => $this->links,
            'languageMenu' => $languageMenu,
            'discover_page_codenames' => $discover_more_page_codenames,
        ];

        $this->pageService->setSharebleVariables($page->servicepoint_id, $page->cta_button_id, $page->cta_heading);

        // Return view
        return view('site.templates.products_show', $viewData);
    }

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function filters()
    {
        $filters = request('filters');
        dd('customize filter function in ProductController');

//        if (sizeof($filters) != 1) {
//            throw abort(404);
//        }
//        $categoryName = $filters[0];
//
//        // Check if category exist else trow 404
//        if ( ! $category = ProductCategoryTranslation::where('slug', $categoryName)
//            ->with('translatable')
//            ->first()) {
//            throw abort(404);
//        }
//
//        $page = $this->pageService->getPageByCodeName('blog');
//        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
//
//        //Get products through the category
//        $products = $category->translatable->products()->paginate(8);
//        $products->withPath('/' . $this->links->blog->route . '/' . $category->slug);
//
//
//        // Return view
//        return \View::make($this->baseViewPath.$this->pagePrefix.'index',[
//            'page' => $page,
//            'links' => $this->links,
//            'otherLanguages' => $otherLanguageRoutes,
//            'products' => $products,
//        ]);
    }




}