1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* CouponGroupController |
5
|
|
|
* |
6
|
|
|
* This is the controller of the coupons of the shop |
7
|
|
|
* @author Matthijs Neijenhuijs <[email protected]> |
8
|
|
|
* @version 0.1 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use App\Http\Controllers\Controller; |
12
|
|
|
use Illuminate\Http\Request; |
13
|
|
|
use Form; |
14
|
|
|
|
15
|
|
|
use Hideyo\Ecommerce\Framework\Services\Coupon\CouponFacade as CouponService; |
16
|
|
|
|
17
|
|
|
class CouponGroupController extends Controller |
18
|
|
|
{ |
19
|
|
|
public function index(Request $request) |
20
|
|
|
{ |
21
|
|
|
if ($request->wantsJson()) { |
22
|
|
|
|
23
|
|
|
$query = CouponService::getGroupModel()->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id); |
|
|
|
|
24
|
|
|
|
25
|
|
|
$datatables = \DataTables::of($query) |
26
|
|
|
->addColumn('action', function ($query) { |
27
|
|
|
$deleteLink = Form::deleteajax(url()->route('coupon-group.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-sm btn-danger')); |
28
|
|
|
$links = '<a href="'.url()->route('coupon-group.edit', $query->id).'" class="btn btn-sm btn-success"><i class="fi-pencil"></i>Edit</a> '.$deleteLink; |
29
|
|
|
return $links; |
30
|
|
|
}); |
31
|
|
|
|
32
|
|
|
return $datatables->make(true); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return view('backend.coupon-group.index')->with('couponGroup', CouponService::selectAll()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function create() |
39
|
|
|
{ |
40
|
|
|
return view('backend.coupon-group.create')->with(array()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function store(Request $request) |
44
|
|
|
{ |
45
|
|
|
$result = CouponService::createGroup($request->all()); |
46
|
|
|
return CouponService::notificationRedirect('coupon-group.index', $result, 'The coupon group was inserted.'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function edit($couponGroupId) |
50
|
|
|
{ |
51
|
|
|
return view('backend.coupon-group.edit')->with(array('couponGroup' => CouponService::findGroup($couponGroupId))); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function update(Request $request, $couponGroupId) |
55
|
|
|
{ |
56
|
|
|
$result = CouponService::updateGroupById($request->all(), $couponGroupId); |
57
|
|
|
return CouponService::notificationRedirect('coupon-group.index', $result, 'The coupon group was updated.'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function destroy($couponGroupId) |
61
|
|
|
{ |
62
|
|
|
$result = CouponService::destroyGroup($couponGroupId); |
63
|
|
|
|
64
|
|
|
if ($result) { |
65
|
|
|
flash('The coupon was deleted.'); |
66
|
|
|
return redirect()->route('coupon-group.index'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|