Passed
Push — master ( 55010d...cba042 )
by Matthijs
06:10
created

ProductAmountOptionController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php namespace App\Http\Controllers\Backend;
2
3
/**
4
 * PaymentAmountOptionController
5
 *
6
 * This is the controller of the product amount options of the shop
7
 * @author Matthijs Neijenhuijs <[email protected]>
8
 * @version 0.1
9
 */
10
11
use App\Http\Controllers\Controller;
12
13
use Dutchbridge\Datatable\ProductAmountOptionDatatable;
0 ignored issues
show
Bug introduced by
The type Dutchbridge\Datatable\ProductAmountOptionDatatable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Hideyo\Ecommerce\Framework\Services\Product\ProductAmountOptionFacade as ProductAmountOptionService;
0 ignored issues
show
Bug introduced by
The type Hideyo\Ecommerce\Framewo...oductAmountOptionFacade was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Hideyo\Ecommerce\Framework\Services\Product\ProductFacade as ProductService;
16
use Hideyo\Ecommerce\Framework\Services\ExtraField\ExtraFieldFacade as ExtraFieldService;
17
use Hideyo\Ecommerce\Framework\Services\Attribute\AttributeFacade as AttributeService;
18
use Hideyo\Ecommerce\Framework\Services\TaxRate\TaxRateFacade as TaxRateService;;
19
20
use Request;
21
use Notification;
22
use DataTables;
23
use Form;
24
25
class ProductAmountOptionController extends Controller
26
{
27
    public function index($productId)
28
    {   
29
        $datatable =  new ProductAmountOptionDatatable();
0 ignored issues
show
Unused Code introduced by
The assignment to $datatable is dead and can be removed.
Loading history...
30
        $product = $this->product->find($productId);
0 ignored issues
show
Bug Best Practice introduced by
The property product does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
31
        if (Request::wantsJson()) {
32
33
            $query = $this->productAmountOption->getModel()->where('product_id', '=', $productId);
0 ignored issues
show
Bug Best Practice introduced by
The property productAmountOption does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
34
            
35
            $datatables = DataTables::of($query)->addColumn('action', function ($query) use ($productId) {
36
                $deleteLink = Form::deleteajax('/admin/product/'.$productId.'/product-amount-option/'. $query->id, 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
37
                $links = '<a href="/admin/product/'.$productId.'/product-amount-option/'.$query->id.'/edit" class="btn btn-default btn-sm btn-success"><i class="entypo-pencil"></i>Edit</a>  '.$deleteLink;
38
                
39
                return $links;
40
            });
41
42
            return $datatables->make(true);
43
        }
44
        
45
        return view('backend.product-amount-option.index')->with(array('product' => $product, 'attributeGroups' => $this->attributeGroup->selectAll()->pluck('title', 'id')));
0 ignored issues
show
Bug Best Practice introduced by
The property attributeGroup does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
46
    }
47
48
    public function create($productId)
49
    {
50
        $product = $this->product->find($productId);
0 ignored issues
show
Bug Best Practice introduced by
The property product does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
51
52
        if (Request::wantsJson()) {
53
            $input = Request::all();
54
            $attributeGroup = $this->attributeGroup->find($input['attribute_group_id']);
0 ignored issues
show
Bug Best Practice introduced by
The property attributeGroup does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
55
            if ($attributeGroup->count()) {
56
                if ($attributeGroup->attributes()) {
57
                    return response()->json($attributeGroup->attributes);
58
                }
59
            }
60
        } else {
61
            return view('backend.product-amount-option.create')->with(array('taxRates' => $this->taxRate->selectAll()->pluck('title', 'id'), 'product' => $product, 'attributeGroups' => $this->attributeGroup->selectAll()->pluck('title', 'id')));
0 ignored issues
show
Bug Best Practice introduced by
The property taxRate does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
62
        }
63
    }
64
65
    public function store($productId)
66
    {
67
68
        $result  = $this->productAmountOption->create(Request::all(), $productId);
0 ignored issues
show
Bug Best Practice introduced by
The property productAmountOption does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
69
 
70
        if (isset($result->id)) {
71
            Notification::success('The product amount option is updated.');
72
            return redirect()->route('admin.product.{productId}.product-amount-option.index', $productId);
73
        }
74
75
        if ($result) {
76
            foreach ($result->errors()->all() as $error) {
77
                Notification::error($error);
78
            }
79
        } else {
80
            Notification::error('amount option already exist');
81
        }
82
        
83
        return redirect()->back()->withInput();
84
    }
85
86
    public function edit($productId, $id)
87
    {
88
        $product = $this->product->find($productId);
0 ignored issues
show
Bug Best Practice introduced by
The property product does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
89
        $productAmountOption = $this->productAmountOption->find($id);
0 ignored issues
show
Bug Best Practice introduced by
The property productAmountOption does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
90
        $selectedAttributes = array();
91
        $attributes = array();
92
93
        return view('backend.product-amount-option.edit')->with(array('taxRates' => $this->taxRate->selectAll()->pluck('title', 'id'), 'selectedAttributes' => $selectedAttributes, 'attributes' => $attributes, 'productAmountOption' => $productAmountOption, 'product' => $product, 'attributeGroups' => $this->attributeGroup->selectAll()->pluck('title', 'id')));
0 ignored issues
show
Bug Best Practice introduced by
The property attributeGroup does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property taxRate does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
94
    }
95
96
    public function update($productId, $id)
97
    {
98
        $result  = $this->productAmountOption->updateById(Request::all(), $productId, $id);
0 ignored issues
show
Bug Best Practice introduced by
The property productAmountOption does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
99
100
        if (!$result->id) {
101
            return redirect()->back()->withInput()->withErrors($result->errors()->all());
102
        }
103
        
104
        Notification::success('The product amount option is updated.');
105
        return redirect()->route('admin.product.{productId}.product-amount-option.index', $productId);
106
    }
107
108
    public function destroy($productId, $id)
109
    {
110
        $result  = $this->productAmountOption->destroy($id);
0 ignored issues
show
Bug Best Practice introduced by
The property productAmountOption does not exist on App\Http\Controllers\Bac...tAmountOptionController. Did you maybe forget to declare it?
Loading history...
111
112
        if ($result) {
113
            Notification::success('The product amount option is deleted.');
114
            return redirect()->route('admin.product.{productId}.product-amount-option.index', $productId);
115
        }
116
    }
117
}
118