2018-10-09 12:02:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Admin\Http\Controllers\Sales;
|
|
|
|
|
|
2020-05-06 17:18:48 +00:00
|
|
|
use Illuminate\Support\Facades\Event;
|
2021-04-25 08:20:07 +00:00
|
|
|
use Webkul\Admin\DataGrids\OrderDataGrid;
|
2018-10-09 12:02:22 +00:00
|
|
|
use Webkul\Admin\Http\Controllers\Controller;
|
2019-07-01 11:33:36 +00:00
|
|
|
use Webkul\Sales\Repositories\OrderRepository;
|
2020-05-06 17:18:48 +00:00
|
|
|
use \Webkul\Sales\Repositories\OrderCommentRepository;
|
2018-10-09 12:02:22 +00:00
|
|
|
|
|
|
|
|
class OrderController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
protected $_config;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* OrderRepository object
|
|
|
|
|
*
|
2020-03-05 13:37:08 +00:00
|
|
|
* @var \Webkul\Sales\Repositories\OrderRepository
|
2018-10-09 12:02:22 +00:00
|
|
|
*/
|
2019-07-01 11:33:36 +00:00
|
|
|
protected $orderRepository;
|
2018-10-09 12:02:22 +00:00
|
|
|
|
2020-05-06 17:18:48 +00:00
|
|
|
/**
|
|
|
|
|
* OrderCommentRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var \Webkul\Sales\Repositories\OrderCommentRepository
|
|
|
|
|
*/
|
|
|
|
|
protected $orderCommentRepository;
|
|
|
|
|
|
2018-10-09 12:02:22 +00:00
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
2020-03-05 05:34:57 +00:00
|
|
|
* @param \Webkul\Sales\Repositories\OrderRepository $orderRepository
|
2020-05-06 17:18:48 +00:00
|
|
|
* @param \Webkul\Sales\Repositories\OrderCommentRepository $orderCommentRepository
|
2018-10-09 12:02:22 +00:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2020-05-06 17:18:48 +00:00
|
|
|
public function __construct(
|
|
|
|
|
OrderRepository $orderRepository,
|
|
|
|
|
OrderCommentRepository $orderCommentRepository
|
|
|
|
|
)
|
2018-10-09 12:02:22 +00:00
|
|
|
{
|
|
|
|
|
$this->_config = request('_config');
|
|
|
|
|
|
2019-07-01 11:33:36 +00:00
|
|
|
$this->orderRepository = $orderRepository;
|
2020-05-06 17:18:48 +00:00
|
|
|
|
|
|
|
|
$this->orderCommentRepository = $orderCommentRepository;
|
2018-10-09 12:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
2019-08-19 09:30:24 +00:00
|
|
|
* @return \Illuminate\View\View
|
2018-10-09 12:02:22 +00:00
|
|
|
*/
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2021-04-25 08:20:07 +00:00
|
|
|
if (request()->ajax()) {
|
|
|
|
|
return app(OrderDataGrid::class)->toJson();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-09 12:02:22 +00:00
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the view for the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
2019-08-19 09:30:24 +00:00
|
|
|
* @return \Illuminate\View\View
|
2018-10-09 12:02:22 +00:00
|
|
|
*/
|
|
|
|
|
public function view($id)
|
|
|
|
|
{
|
2019-07-01 11:33:36 +00:00
|
|
|
$order = $this->orderRepository->findOrFail($id);
|
2018-10-09 12:02:22 +00:00
|
|
|
|
|
|
|
|
return view($this->_config['view'], compact('order'));
|
|
|
|
|
}
|
2018-10-15 10:39:09 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cancel action for the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function cancel($id)
|
|
|
|
|
{
|
2019-07-01 11:33:36 +00:00
|
|
|
$result = $this->orderRepository->cancel($id);
|
2019-02-13 12:12:07 +00:00
|
|
|
|
2019-01-15 11:54:41 +00:00
|
|
|
if ($result) {
|
2019-02-13 12:12:07 +00:00
|
|
|
session()->flash('success', trans('admin::app.response.cancel-success', ['name' => 'Order']));
|
2018-10-15 10:39:09 +00:00
|
|
|
} else {
|
2019-02-13 12:12:07 +00:00
|
|
|
session()->flash('error', trans('admin::app.response.cancel-error', ['name' => 'Order']));
|
2018-10-15 10:39:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
2020-05-06 17:18:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add comment to the order
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function comment($id)
|
|
|
|
|
{
|
|
|
|
|
$data = array_merge(request()->all(), [
|
|
|
|
|
'order_id' => $id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$data['customer_notified'] = isset($data['customer_notified']) ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
Event::dispatch('sales.order.comment.create.before', $data);
|
|
|
|
|
|
|
|
|
|
$comment = $this->orderCommentRepository->create($data);
|
|
|
|
|
|
|
|
|
|
Event::dispatch('sales.order.comment.create.after', $comment);
|
|
|
|
|
|
|
|
|
|
session()->flash('success', trans('admin::app.sales.orders.comment-added-success'));
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
2018-10-15 10:39:09 +00:00
|
|
|
}
|