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/farmfun.komma.pro/app/Komma/Availability/_AvailabilityController.php
<?php

namespace App\Komma\Availability;

use App\Komma\Availability\Types\Availability;
use App\Komma\Base\Controller;
use App\Komma\Components\ComponentService;
use App\Komma\Locations\LocationService;
use App\Komma\Locations\Models\Location;
use App\Komma\ProductCategories\Models\ProductCategory;
use App\Komma\Products\Models\Product;
use App\Komma\Products\Models\ProductTranslation;

final class _AvailabilityController extends Controller
{
    /** @var AvailabilityService availabilityService */
    private $availabilityService;

    public function __construct()
    {
        parent::__construct();
        $this->availabilityService = app(AvailabilityService::class);
    }

    public function search()
    {
        $page = $this->links->products->node;
        $this->availabilityService->updateSearchSession();

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

        // Check if we should redirect because of the search amount value
        if ($redirect = $this->availabilityService->checkIfShouldRedirect()) {
            return $redirect;
        }

        // Get the available products, note that we get the get the search settings from the session
        $availabilityResults = $this->availabilityService->getAvailabilityResultCollection();

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

    public function show()
    {
        /** @var LocationService $locationService */
        $locationService = app(LocationService::class);

        /** @var Location $location */
        $location = $locationService->getLocationById(request()->get('location_id'));
        $location->load('availability');

        /** @var Product $product */
        $product = $location->boundProducts()->where('product_id', request()->get('product_id'))->first();

//        $product->load('quoteImage', 'detailImages');
        $product->load('quoteImage', 'overviewImage');
        if ($product->hide_on_site) {
            abort(404);
        }

        $availability = new Availability($product, $location);

        // Check if the product has been found through the bound products
        // Else we want to throw an 404 abort
        if (! isset($product)) {
            // If we are local throw exception, else abort application as it's a 404
            if (! app()->environment('local')) {
                return app()->abort(404);
            }
            throw new \UnexpectedValueException(self::class.': The Product "'.ProductTranslation::where('product_id', request()->get('product_id'))->first()->name.'" was not found within bound products of the location "'.$location->translation->name.'". Therefor throw a 404.');
        }

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

        $otherAvailableResults = $this->availabilityService->getAmountOfRandomAvailabilitiesForLocationWhereNot($location, 2, [$product->id]);

        $view = 'availability_show';
//        if($product->code_name === 'bumperball') $view = 'bumperball';

        return view('site.templates.'.$view, [
            'page' => $page,
            'links' => $this->links,
            'availability' => $availability,
            'product' => $product,
            'location' => $location,
            'otherAvailableResults' => $otherAvailableResults,
        ]);
    }

    public function searchWithinCategory(ProductCategory $productCategory)
    {
        $page = $this->links->products->node;
        $this->availabilityService->updateSearchSession();

        // Check if we should redirect because of the search amount value
        if ($redirect = $this->availabilityService->checkIfShouldRedirect()) {
            return $redirect;
        }

        $productCategory->load('translation', 'products');

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

        // Append the product category filter before getting the availability result collection
        $this->availabilityService->setProductCategoryFilter($productCategory);

        // Get the available products, note that we get the get the search settings from the session
        $availabilityResults = $this->availabilityService->getAvailabilityResultCollection();

        // Sort availability as defined in the product category
        $availabilityResults->sortByProductCategory($productCategory);

        // Return view
        return view('site.templates.availability_index', [
            'page' => $page,
            'links' => $this->links,
            'activeProductCategory' => $productCategory,
            'components' => $components,
            'availabilityResults' => $availabilityResults,
        ]);
    }
}