File: D:/HostingSpaces/SBogers10/rentman2019.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 = 10;
$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 {
/** @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'));
}
}
}