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

namespace App\Komma\Products;

use App\Http\Controllers\Controller;
use App\Komma\Components\ComponentService;
use App\Komma\Products\Models\Product;

class ProductController extends Controller
{
    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function index()
    {
        if (! isset($this->links->products)) {
            return abort(404);
        }

        // Get the page through the set links
        $page = $this->links->products->node;

        // Get all products
        $products = $this->productService->getAllProducts();

        // Make language menu for index page
        $languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->products, $this->links->home);

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

    /**
     * @param Product $product
     * @return \Illuminate\Contracts\View\View
     * @throws \ReflectionException
     */
    public function show(Product $product)
    {
        if (! isset($this->links->products)) {
            return abort(404);
        }

        $product->load('images', 'translation', 'translations', 'translation.componentAreas');

        $this->checkIfModelShouldThrowAbort($product);

        $page = $this->links->products->node;

        /** @var $componentService ComponentService */
        $componentService = \App::make(ComponentService::class);
        $components = $componentService->getViewComponents($product->translation);

        // Make language menu for found index page
        $languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->products);
        $this->pageService->extendLanguageMenuWithResource($languageMenu, $product, $this->links->home);

        // Return view
        return \View::make('site.templates.products_show', [
            'page' => $page,
            'product' => $product,
            'components' => $components,
            'links' => $this->links,
            'languageMenu' => $languageMenu,
            'alterHeadings' => true,
            'images' => $product->languageImages(),
        ]);
    }

    /**
     * Create export of the translatable variable of all the products
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function oneSkyExport()
    {
        \App::changeLanguageByIso2('en');

        $products = $this->site
            ->products()
            ->where('lft', '!=', 1)
            ->orderBy('lft', 'asc')
            ->with('translation')
            ->has('translation')
            ->get();

        $exportJson = [];

        foreach ($products as $product) {
            // Generate the page JSON
            $productJson = $this->oneSkyExporterService->generateModelJson($product, ['name', 'visual_name', 'description', 'meta_title', 'meta_description', 'hero_description']);

            if (count($productJson) == 0) {
                continue;
            }

            // Generate the components JSON
            $componentsJson = $this->oneSkyExporterService->generateComponentJson($product->translation);
            if (count($componentsJson) !== 0) {
                $productJson['components'] = $componentsJson;
            }
            $exportJson['product_'.$product->id] = $productJson;
        }

        return response()->json($exportJson);
    }
}