ProductAmountOptionController::create()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 9
c 1
b 0
f 1
nc 4
nop 1
dl 0
loc 14
rs 9.9666
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 DataTables;
22
use Form;
23
24
class ProductAmountOptionController extends Controller
25
{
26
    public function index($productId)
27
    {   
28
        $datatable =  new ProductAmountOptionDatatable();
0 ignored issues
show
Unused Code introduced by
The assignment to $datatable is dead and can be removed.
Loading history...
29
        $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...
30
        if (Request::wantsJson()) {
31
32
            $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...
33
            
34
            $datatables = DataTables::of($query)->addColumn('action', function ($query) use ($productId) {
35
                $deleteLink = Form::deleteajax('/admin/product/'.$productId.'/product-amount-option/'. $query->id, 'Delete', '', array('class'=>'btn btn-default btn-sm btn-danger'));
36
                $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;
37
                
38
                return $links;
39
            });
40
41
            return $datatables->make(true);
42
        }
43
        
44
        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...
45
    }
46
47
    public function create($productId)
48
    {
49
        $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...
50
51
        if (Request::wantsJson()) {
52
            $input = Request::all();
53
            $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...
54
            if ($attributeGroup->count()) {
55
                if ($attributeGroup->attributes()) {
56
                    return response()->json($attributeGroup->attributes);
57
                }
58
            }
59
        } else {
60
            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...
61
        }
62
    }
63
64
    public function store($productId)
65
    {
66
67
        $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...
68
 
69
        if (isset($result->id)) {
70
            flash('The product amount option is updated.');
71
            return redirect()->route('admin.product.{productId}.product-amount-option.index', $productId);
72
        }
73
74
        if ($result) {
75
            foreach ($result->errors()->all() as $error) {
76
                flash($error);
77
            }
78
        } else {
79
            flash('amount option already exist');
80
        }
81
        
82
        return redirect()->back()->withInput();
83
    }
84
85
    public function edit($productId, $id)
86
    {
87
        $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...
88
        $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...
89
        $selectedAttributes = array();
90
        $attributes = array();
91
92
        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...
93
    }
94
95
    public function update($productId, $id)
96
    {
97
        $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...
98
99
        if (!$result->id) {
100
            return redirect()->back()->withInput()->withErrors($result->errors()->all());
101
        }
102
        
103
        flash('The product amount option is updated.');
104
        return redirect()->route('admin.product.{productId}.product-amount-option.index', $productId);
105
    }
106
107
    public function destroy($productId, $id)
108
    {
109
        $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...
110
111
        if ($result) {
112
            flash('The product amount option is deleted.');
113
            return redirect()->route('admin.product.{productId}.product-amount-option.index', $productId);
114
        }
115
    }
116
}
117