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

109 lines
2.5 KiB
PHP
Raw Normal View History

2018-10-17 07:21:47 +00:00
<?php
namespace Webkul\Customer\Http\Controllers;
2018-10-17 07:21:47 +00:00
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Sales\Repositories\OrderRepository;
use Webkul\Sales\Repositories\InvoiceRepository;
2018-10-17 07:21:47 +00:00
use Auth;
use PDF;
2018-10-17 07:21:47 +00:00
/**
* Customer controlller for the customer basically for the tasks of customers
* which will be done after customer authenticastion.
*
* @author Prashant Singh <prashant.singh852@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class OrderController extends Controller
{
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
/**
* OrderrRepository object
*
* @var array
*/
protected $order;
/**
* InvoiceRepository object
*
* @var array
*/
protected $invoice;
2018-10-17 07:21:47 +00:00
/**
* Create a new controller instance.
*
* @param \Webkul\Order\Repositories\OrderRepository $order
* @param \Webkul\Order\Repositories\InvoiceRepository $invoice
2018-10-17 07:21:47 +00:00
* @return void
*/
public function __construct(
OrderRepository $order,
InvoiceRepository $invoice
)
2018-10-17 07:21:47 +00:00
{
$this->middleware('customer');
$this->_config = request('_config');
$this->order = $order;
$this->invoice = $invoice;
2018-10-17 07:21:47 +00:00
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
2019-02-20 13:41:46 +00:00
public function index()
{
$orders = auth()->guard('customer')->user()->all_orders;
2018-10-17 07:21:47 +00:00
return view($this->_config['view'], compact('orders'));
}
/**
* Show the view for the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function view($id)
{
2019-03-31 20:02:58 +00:00
$orders = auth()->guard('customer')->user()->all_orders;
if(isset($orders) && count($orders)) {
$order = $orders->first();
return view($this->_config['view'], compact('order'));
} else {
return redirect()->route( 'customer.orders.index');
}
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)
{
$invoice = $this->invoice->find($id);
$pdf = PDF::loadView('shop::customers.account.orders.pdf', compact('invoice'))->setPaper('a4');
return $pdf->download('invoice-' . $invoice->created_at->format('d-m-Y') . '.pdf');
}
2019-03-31 20:02:58 +00:00
}