sarga/packages/Webkul/Shop/src/Http/Controllers/OrderController.php

113 lines
2.7 KiB
PHP
Raw Normal View History

2018-10-17 07:21:47 +00:00
<?php
2019-04-09 08:35:57 +00:00
namespace Webkul\Shop\Http\Controllers;
2018-10-17 07:21:47 +00:00
2021-03-01 06:42:44 +00:00
use PDF;
2018-10-17 07:21:47 +00:00
use Webkul\Sales\Repositories\OrderRepository;
use Webkul\Sales\Repositories\InvoiceRepository;
2018-10-17 07:21:47 +00:00
class OrderController extends Controller
{
/**
* OrderrRepository object
*
2020-03-05 13:37:08 +00:00
* @var \Webkul\Sales\Repositories\OrderRepository
2018-10-17 07:21:47 +00:00
*/
2019-07-01 11:33:36 +00:00
protected $orderRepository;
2018-10-17 07:21:47 +00:00
/**
* InvoiceRepository object
*
2020-03-05 13:37:08 +00:00
* @var \Webkul\Sales\Repositories\InvoiceRepository
*/
2019-07-01 11:33:36 +00:00
protected $invoiceRepository;
2018-10-17 07:21:47 +00:00
/**
* Create a new controller instance.
*
2020-03-05 13:37:08 +00:00
* @param \Webkul\Order\Repositories\OrderRepository $orderRepository
* @param \Webkul\Order\Repositories\InvoiceRepository $invoiceRepository
2018-10-17 07:21:47 +00:00
* @return void
*/
public function __construct(
2019-07-01 11:33:36 +00:00
OrderRepository $orderRepository,
InvoiceRepository $invoiceRepository
)
2018-10-17 07:21:47 +00:00
{
$this->middleware('customer');
2019-07-01 11:33:36 +00:00
$this->orderRepository = $orderRepository;
2019-07-01 11:33:36 +00:00
$this->invoiceRepository = $invoiceRepository;
2020-02-06 11:48:51 +00:00
parent::__construct();
2018-10-17 07:21:47 +00:00
}
/**
* Display a listing of the resource.
*
2019-12-11 09:55:19 +00:00
* @return \Illuminate\View\View
2018-10-17 07:21:47 +00:00
*/
2019-06-28 14:18:52 +00:00
public function index()
{
return view($this->_config['view']);
2018-10-17 07:21:47 +00:00
}
/**
* Show the view for the specified resource.
*
* @param int $id
2019-12-11 09:55:19 +00:00
* @return \Illuminate\View\View
2018-10-17 07:21:47 +00:00
*/
public function view($id)
{
2019-07-01 11:33:36 +00:00
$order = $this->orderRepository->findOneWhere([
2019-04-09 08:35:57 +00:00
'customer_id' => auth()->guard('customer')->user()->id,
2020-03-04 06:32:53 +00:00
'id' => $id,
2019-04-09 08:35:57 +00:00
]);
2019-03-31 20:02:58 +00:00
2020-02-20 07:05:51 +00:00
if (! $order) {
2019-04-09 08:35:57 +00:00
abort(404);
2020-02-20 07:05:51 +00:00
}
2019-03-31 20:02:58 +00:00
2019-04-09 08:35:57 +00:00
return view($this->_config['view'], compact('order'));
2018-10-17 07:21:47 +00:00
}
/**
* Print and download the for the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function print($id)
{
2019-07-01 11:33:36 +00:00
$invoice = $this->invoiceRepository->findOrFail($id);
2021-03-01 06:42:44 +00:00
if ($invoice->order->customer_id !== auth()->guard('customer')->user()->id) {
abort(404);
}
$pdf = PDF::loadView('shop::customers.account.orders.pdf', compact('invoice'))->setPaper('a4');
return $pdf->download('invoice-' . $invoice->created_at->format('d-m-Y') . '.pdf');
}
2020-04-27 07:26:09 +00:00
/**
* Cancel action for the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function cancel($id)
{
$result = $this->orderRepository->cancel($id);
if ($result) {
session()->flash('success', trans('admin::app.response.cancel-success', ['name' => 'Order']));
} else {
session()->flash('error', trans('admin::app.response.cancel-error', ['name' => 'Order']));
}
return redirect()->back();
}
2019-04-09 08:35:57 +00:00
}