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/helder.komma.pro/app/Komma/Shop/Orders/Kms/OrderController.php
<?php

namespace App\Komma\Shop\Orders\Kms;

/**
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

use App\Komma\Globalization\RegionInfo;
use App\Komma\Kms\Core\SectionController;
use App\Komma\Shop\Orders\Models\Order;
use App\Komma\Shop\Orders\SearchRequest;

class OrderController extends SectionController
{
    protected $slug = "orders";
    protected $forModelName = Order::class;

    /** @var OrderService */
    private $orderService;

    /**
     * Constructor
     * @param OrderSection $section
     * @param OrderService $orderService
     */
    public function __construct(OrderSection $section, OrderService $orderService)
    {
        parent::__construct($section);

        $this->treeService->setSectionService($this->section->getSectionService());
        $this->treeService->setForModelName(new Order());
        $this->orderService = $orderService;
    }

    /**
     * This method is called on the overview page.
     * It will render the section and view.
     *
     * @return mixed
     * @throws \Illuminate\Auth\Access\AuthorizationException
     */
    public function index()
    {
        $this->authorize('index', $this->forModelName);

        /** @var OrderSection $section */
        $section = $this->section;

        $shopRegionInfo = new RegionInfo('NL'); //Shop was build with euros in mind and the Dutch language as the primary one

        $amount = 20;
        $ordersCollection = $this->orderService->getLatest($amount)->get();

        $section->setForModelName($this->forModelName);

        $view = $section->renderOrderIndex();
        $view->with('orders', $ordersCollection)
            ->with('shopRegionInfo', $shopRegionInfo)
            ->with('resultsTypeTranslation', __('shop/orders.latest_orders', ['amount' => $amount]));
        return $view;
    }

    /**
     * Search for orders
     *
     * @param SearchRequest $request
     * @return \Illuminate\Contracts\View\View|\Illuminate\Http\Resources\Json\AnonymousResourceCollection
     */
    public function OrderSearch(SearchRequest $request)
    {
        $resultsPerPage = (is_numeric(\Input::get('perPage')) ? (int) \Input::get('perPage') : 5);
        $ordersCollection = $this->orderService->search(\Input::all())->orderBy('created_at', 'desc')->paginate($resultsPerPage);
        $ordersCollection->appends(\Input::all()); //Add existing query string parameters to the current pagination links

        $shopRegionInfo = new RegionInfo('NL'); //Shop was build with euros in mind and the Dutch language as the primary one

        if(request()->ajax()) {
            //Return results as json
            return \App\Komma\Shop\Orders\Resources\Order::collection($ordersCollection);
        } else {
            $request->flash();

            /** @var OrderSection $section */
            $section = $this->section;

            $section->setForModelName($this->forModelName);
            $view = $section->renderOrderIndex();
            return $view->with('orders', $ordersCollection)
                        ->with('shopRegionInfo', $shopRegionInfo)
                        ->with('perPage', $resultsPerPage)
                        ->with('resultsTypeTranslation', __('shop/orders.search_results'));
        }
    }
}