|
1
|
|
|
<?php namespace App\Http\Controllers\Backend; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AttributeGroupController |
|
5
|
|
|
* |
|
6
|
|
|
* This is the controller of the attributes groups used by products 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 DataTables; |
|
14
|
|
|
use Form; |
|
15
|
|
|
|
|
16
|
|
|
use Hideyo\Ecommerce\Framework\Services\Attribute\AttributeFacade as AttributeService; |
|
17
|
|
|
|
|
18
|
|
|
class AttributeGroupController extends Controller |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Display a listing of the resource. |
|
22
|
|
|
* @param \Illuminate\Http\Request $request |
|
23
|
|
|
* @param integer $attributeGroupId for relation with attributeGroup |
|
24
|
|
|
* @return View |
|
|
|
|
|
|
25
|
|
|
* @return datatables |
|
26
|
|
|
*/ |
|
27
|
|
|
public function index(Request $request) |
|
28
|
|
|
{ |
|
29
|
|
|
if ($request->wantsJson()) { |
|
30
|
|
|
$query = AttributeService::getGroupModel()->where('shop_id', '=', auth('hideyobackend')->user()->selected_shop_id); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
$datatables = DataTables::of($query)->addColumn('action', function ($query) { |
|
33
|
|
|
$deleteLink = Form::deleteajax(url()->route('attribute-group.destroy', $query->id), 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger')); |
|
34
|
|
|
$links = ' |
|
35
|
|
|
<a href="'.url()->route('attribute.index', $query->id).'" class="btn btn-sm btn-info"><i class="entypo-pencil"></i>'.$query->attributes->count().' Attributes</a> |
|
36
|
|
|
<a href="'.url()->route('attribute-group.edit', $query->id).'" class="btn btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a> |
|
37
|
|
|
'.$deleteLink; |
|
38
|
|
|
return $links; |
|
39
|
|
|
}); |
|
40
|
|
|
|
|
41
|
|
|
return $datatables->make(true); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return view('backend.attribute-group.index'); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function create() |
|
48
|
|
|
{ |
|
49
|
|
|
return view('backend.attribute-group.create'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function store(Request $request) |
|
53
|
|
|
{ |
|
54
|
|
|
$result = AttributeService::createGroup($request->all()); |
|
55
|
|
|
return AttributeService::notificationRedirect('attribute-group.index', $result, 'The attribute group was inserted.'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function edit($attributeGroupId) |
|
59
|
|
|
{ |
|
60
|
|
|
return view('backend.attribute-group.edit')->with(array('attributeGroup' => AttributeService::findGroup($attributeGroupId))); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function update(Request $request, $attributeGroupId) |
|
64
|
|
|
{ |
|
65
|
|
|
$result = AttributeService::updateGroupById($request->all(), $attributeGroupId); |
|
66
|
|
|
return AttributeService::notificationRedirect('attribute-group.index', $result, 'The attribute group was updated.'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function destroy($attributeGroupId) |
|
70
|
|
|
{ |
|
71
|
|
|
$result = AttributeService::destroyGroup($attributeGroupId); |
|
72
|
|
|
|
|
73
|
|
|
if ($result) { |
|
74
|
|
|
flash('Attribute group was deleted.'); |
|
75
|
|
|
return redirect()->route('attribute-group.index'); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|