|
1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
|
2
|
|
|
|
|
3
|
|
|
use App\Http\Controllers\Controller; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* CouponController |
|
7
|
|
|
* |
|
8
|
|
|
* This is the controller for the shop clients |
|
9
|
|
|
* @author Matthijs Neijenhuijs <[email protected]> |
|
10
|
|
|
* @version 0.1 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
use Hideyo\Ecommerce\Framework\Services\Coupon\CouponFacade as CouponService; |
|
15
|
|
|
|
|
16
|
|
|
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService; |
|
17
|
|
|
use Hideyo\Ecommerce\Framework\Services\ProductCategory\ProductCategoryFacade as ProductCategoryService; |
|
18
|
|
|
use Hideyo\Ecommerce\Framework\Services\SendingMethod\SendingMethodFacade as SendingMethodService; |
|
19
|
|
|
use Hideyo\Ecommerce\Framework\Services\PaymentMethod\PaymentMethodFacade as PaymentMethodService; |
|
20
|
|
|
|
|
21
|
|
|
use Illuminate\Http\Request; |
|
22
|
|
|
use DataTables; |
|
23
|
|
|
use Form; |
|
24
|
|
|
|
|
25
|
|
|
class CouponController extends Controller |
|
26
|
|
|
{ |
|
27
|
|
|
public function index(Request $request) |
|
28
|
|
|
{ |
|
29
|
|
|
if ($request->wantsJson()) { |
|
30
|
|
|
$query = CouponService::getModel() |
|
31
|
|
|
->where(CouponService::getModel()->getTable().'.shop_id', '=', auth('hideyobackend')->user()->selected_shop_id) |
|
|
|
|
|
|
32
|
|
|
->with(array('couponGroup')); |
|
33
|
|
|
|
|
34
|
|
|
$datatables = DataTables::of($query) |
|
35
|
|
|
->filterColumn('title', function ($query, $keyword) { |
|
36
|
|
|
$query->whereRaw("coupon.title like ?", ["%{$keyword}%"]); |
|
37
|
|
|
}) |
|
38
|
|
|
|
|
39
|
|
|
->addColumn('action', function ($query) { |
|
40
|
|
|
$deleteLink = Form::deleteajax('/admin/coupon/'. $query->id, 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
|
41
|
|
|
$links = '<a href="/admin/coupon/'.$query->id.'/edit" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> '.$deleteLink; |
|
42
|
|
|
|
|
43
|
|
|
return $links; |
|
44
|
|
|
}); |
|
45
|
|
|
|
|
46
|
|
|
return $datatables->make(true); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return view('backend.coupon.index')->with('coupon', CouponService::selectAll()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function create() |
|
53
|
|
|
{ |
|
54
|
|
|
return view('backend.coupon.create')->with(array( |
|
55
|
|
|
'products' => ProductService::selectAll()->pluck('title', 'id'), |
|
56
|
|
|
'productCategories' => ProductCategoryService::selectAll()->pluck('title', 'id'), |
|
57
|
|
|
'groups' => CouponService::selectAllGroups()->pluck('title', 'id')->toArray(), |
|
58
|
|
|
'sendingMethods' => SendingMethodService::selectAll()->pluck('title', 'id'), |
|
59
|
|
|
'paymentMethods' => PaymentMethodService::selectAll()->pluck('title', 'id') |
|
60
|
|
|
)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function store(Request $request) |
|
64
|
|
|
{ |
|
65
|
|
|
$result = CouponService::create($request->all()); |
|
66
|
|
|
return CouponService::notificationRedirect('coupon.index', $result, 'The coupon was inserted.'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function edit($couponId) |
|
70
|
|
|
{ |
|
71
|
|
|
return view('backend.coupon.edit')->with( |
|
72
|
|
|
array( |
|
73
|
|
|
'coupon' => CouponService::find($couponId), |
|
74
|
|
|
'products' => ProductService::selectAll()->pluck('title', 'id'), |
|
75
|
|
|
'groups' => CouponService::selectAllGroups()->pluck('title', 'id')->toArray(), |
|
76
|
|
|
'productCategories' => ProductCategoryService::selectAll()->pluck('title', 'id'), |
|
77
|
|
|
'sendingMethods' => SendingMethodService::selectAll()->pluck('title', 'id'), |
|
78
|
|
|
'paymentMethods' => PaymentMethodService::selectAll()->pluck('title', 'id'), |
|
79
|
|
|
) |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function update(Request $request, $couponId) |
|
84
|
|
|
{ |
|
85
|
|
|
$result = CouponService::updateById($request->all(), $couponId); |
|
86
|
|
|
return CouponService::notificationRedirect('coupon.index', $result, 'The coupon was updated.'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function destroy($couponId) |
|
90
|
|
|
{ |
|
91
|
|
|
$result = CouponService::destroy($couponId); |
|
92
|
|
|
|
|
93
|
|
|
if ($result) { |
|
94
|
|
|
flash('The coupon was deleted.'); |
|
95
|
|
|
return redirect()->route('coupon.index'); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|