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

namespace App\Komma\Products;

use App\Komma\Base\Controller;
use App\Komma\Components\ComponentService;
use App\Komma\ProductCategories\Models\ProductCategory;
use App\Komma\Products\Models\Product;
use App\Komma\ShoppingCart\Interfaces\ShoppingCartInterface;

class ProductController extends Controller
{
    /** @var ProductService */
    private $productService;

    /** @var string */
    private $postPaginationKey = 'postPagination';

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

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

        $page->load('heroImages');

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

        $productCategories = ProductCategory::where('active', 1)
            ->with('translation', 'products.translation', 'products.locations', 'products.images')
            ->has('products')
            ->has('translation')
            ->orderBy('lft')
            ->get();


        /** @var ShoppingCartInterface $shoppingCart */
        $shoppingCart = app()->make(ShoppingCartInterface::class);
        $cartLocation = $shoppingCart->getItemsCount() === 0 ? null : $shoppingCart->getLocation();

        if (isset(request()->prices)) {
            $showPrices = request()->prices == 'inc';
        } else {
            $showPrices = true;
        }

        return view('site.templates.products_index', [
            'page' => $page,
            'links' => $this->links,
            'components' => $components,
            'productCategories' => $productCategories,
            'cartLocation' => $cartLocation,
            'showPricesInc' => $showPrices,
            'shoppingCart' => $shoppingCart,
        ]);
    }

    /**
     * @param Product $product
     * @return \Illuminate\Contracts\View\View
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function show(Product $product)
    {
        if (! $product->active || $product->hide_on_site) {
            abort(404);
        }
        $product->load('translation', 'quoteImage', 'overviewImage');

        /** @var ShoppingCartInterface $shoppingCart */
        $shoppingCart = app()->make(ShoppingCartInterface::class);
        $cartLocation = $shoppingCart->getItemsCount() === 0 ? null : $shoppingCart->getLocation();

        if (! $cartLocation) {
            $otherProducts = $this->productService->getOtherProducts($product, $product->product_type);
        } else {
            $notSelectedProducts = $cartLocation->boundProducts->whereNotIn('id', $shoppingCart->getProducts()->pluck('id')->toArray());
            $otherProducts = $this->productService->getActivityProductsWhereIn($notSelectedProducts->pluck('id')->toArray());
        }

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

        return view('site.templates.products_show', [
            'page' => $page,
            'links' => $this->links,
            'product' => $product,
            'otherProducts' => $otherProducts,
            'showPricesInc' => '',
        ]);
    }

    public function category(ProductCategory $productCategory)
    {
        $productCategory->load('translation', 'products');
        $page = $this->links->products->node;

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

        $products = $this->productService->getActivityProductsWhereIn($productCategory->products->pluck('id')->toArray(), 9999);
        $products->load('locations');

        /** @var ShoppingCartInterface $shoppingCart */
        $shoppingCart = app()->make(ShoppingCartInterface::class);
        $cartLocation = $shoppingCart->getItemsCount() === 0 ? null : $shoppingCart->getLocation();

        foreach ($products as $product) {
            if (! $cartLocation) {
                $product->available_for_location = true;
                continue;
            }

            $product->available_for_location = $product->availableForLocation($cartLocation);
        }

        $products = $products->sortByDesc('available_for_location');

        if (isset(request()->prices)) {
            $showPrices = request()->prices == 'inc';
        } else {
            $showPrices = true;
        }

        return view('site.templates.products_index', [
            'page' => $page,
            'links' => $this->links,
            'components' => $components,
            'products' => $products,
            'cartLocation' => $cartLocation,
            'productCategory' => $productCategory,
            'showPricesInc' => $showPrices,
        ]);
    }
}