Completed
Push — development ( 5f50c9...3496bb )
by Ashutosh
11:44 queued 10s
created

ProductController   D

Complexity

Total Complexity 59

Size/Duplication

Total Lines 646
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 59
eloc 349
dl 0
loc 646
rs 4.08
c 0
b 0
f 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
B getProducts() 0 58 7
A __construct() 0 40 1
A index() 0 8 2
A create() 0 24 2
A save() 0 24 3
A uploadUpdate() 0 17 2
A getUpload() 0 36 1
B store() 0 56 6
A getSubscriptionCheckScript() 0 15 1
A getProductField() 0 21 4
A edit() 0 26 2
B destroy() 0 55 6
A adminDownload() 0 24 5
A update() 0 45 5
A saveTax() 0 13 3
B fileDestroy() 0 49 6
A downloadProduct() 0 21 3

How to fix   Complexity   

Complex Class

Complex classes like ProductController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ProductController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace App\Http\Controllers\Product;
4
5
// use Illuminate\Http\Request;
6
    use App\Model\Order\Order;
7
    use App\Model\Payment\Currency;
8
    use App\Model\Payment\Period;
9
    use App\Model\Payment\Plan;
10
    use App\Model\Payment\Tax;
11
    use App\Model\Payment\TaxClass;
12
    use App\Model\Payment\TaxProductRelation;
13
    use App\Model\Product\Price;
14
    use App\Model\Product\Product;
15
    use App\Model\Product\ProductGroup;
16
    use App\Model\Product\ProductUpload;
17
    use App\Model\Product\Subscription;
18
    use App\Model\Product\Type;
19
    use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
20
    use Illuminate\Http\Request;
21
    use Illuminate\Support\Facades\Input;
22
    use Spatie\Activitylog\Models\Activity;
23
24
    // use Input;
25
26
    class ProductController extends BaseProductController
27
    {
28
        public $product;
29
        public $price;
30
        public $type;
31
        public $subscription;
32
        public $currency;
33
        public $group;
34
        public $plan;
35
        public $tax;
36
        public $tax_relation;
37
        public $tax_class;
38
        public $product_upload;
39
40
        public function __construct()
41
        {
42
            $this->middleware('auth');
43
            $this->middleware('admin', ['except' => ['adminDownload', 'userDownload']]);
44
45
            $product = new Product();
46
            $this->product = $product;
47
48
            $price = new Price();
49
            $this->price = $price;
50
51
            $type = new Type();
52
            $this->type = $type;
53
54
            $subscription = new Subscription();
55
            $this->subscription = $subscription;
56
57
            $currency = new Currency();
58
            $this->currency = $currency;
59
60
            $group = new ProductGroup();
61
            $this->group = $group;
62
63
            $plan = new Plan();
64
            $this->plan = $plan;
65
66
            $tax = new Tax();
67
            $this->tax = $tax;
68
69
            $period = new Period();
70
            $this->period = $period;
71
72
            $tax_relation = new TaxProductRelation();
73
            $this->tax_relation = $tax_relation;
74
75
            $tax_class = new TaxClass();
76
            $this->tax_class = $tax_class;
77
78
            $product_upload = new ProductUpload();
79
            $this->product_upload = $product_upload;
80
        }
81
82
        /**
83
         * Display a listing of the resource.
84
         *
85
         * @return \Response
86
         */
87
        public function index()
88
        {
89
            try {
90
                return view('themes.default1.product.product.index');
91
            } catch (\Exception $e) {
92
                Bugsnag::notifyException($e);
93
94
                return redirect('/')->with('fails', $e->getMessage());
95
            }
96
        }
97
98
        /**
99
         * Display a listing of the resource.
100
         *
101
         * @return \Response
102
         */
103
        public function getProducts()
104
        {
105
            try {
106
                $new_product = Product::select('id', 'name', 'type', 'group')->get();
107
108
                return\ DataTables::of($new_product)
109
            // return \Datatable::collection($this->product->select('id', 'name', 'type', 'group')->where('id', '!=', 1)->get())
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
110
                            ->addColumn('checkbox', function ($model) {
111
                                return "<input type='checkbox' class='product_checkbox' value=".$model->id.' name=select[] id=check>';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 134 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
112
                            })
113
                            ->addColumn('name', function ($model) {
114
                                return ucfirst($model->name);
115
                            })
116
                            ->addColumn('type', function ($model) {
117
                                //dd($model->type());
118
                                if ($this->type->where('id', $model->type)->first()) {
119
                                    return $this->type->where('id', $model->type)->first()->name;
120
                                } else {
121
                                    return 'Not available';
122
                                }
123
                            })
124
                            ->addColumn('group', function ($model) {
125
                                //dd($model->type());
126
                                if ($this->group->where('id', $model->group)->first()) {
127
                                    return $this->group->where('id', $model->group)->first()->name;
128
                                } else {
129
                                    return 'Not available';
130
                                }
131
                            })
132
                            ->addColumn('price', function ($model) {
133
                                if ($this->price->where('product_id', $model->id)->first()) {
134
                                    return $this->price->where('product_id', $model->id)->first()->price;
135
                                } else {
136
                                    return 'Not available';
137
                                }
138
                            })
139
                            ->addColumn('currency', function ($model) {
140
                                if ($this->price->where('product_id', $model->id)->first()) {
141
                                    return $this->price->where('product_id', $model->id)->first()->currency;
142
                                } else {
143
                                    return 'Not available';
144
                                }
145
                            })
146
                            ->addColumn('Action', function ($model) {
147
                                $url = '';
148
                                if ($model->type == 2) {
149
                                    $url = '<a href='.url('product/download/'.$model->id)." class='btn btn-sm btn-primary btn-xs'><i class='fa fa-download' style='color:white;'> </i>&nbsp;&nbsp;Download</a>";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 208 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
150
                                }
151
152
                                return '<p><a href='.url('products/'.$model->id.'/edit')." class='btn btn-sm btn-primary btn-xs'><i class='fa fa-edit' style='color:white;'> </i>&nbsp;&nbsp;Edit</a>&nbsp;$url</p>";
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 213 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
153
                            })
154
155
                            ->rawColumns(['checkbox', 'name', 'type', 'group', 'price', 'currency', 'Action'])
156
                            ->make(true);
157
            } catch (\Exception $e) {
158
                Bugsnag::notifyException($e);
159
160
                return redirect()->back()->with('fails', $e->getMessage());
161
            }
162
        }
163
164
        public function getUpload($id)
165
        {
166
            $new_upload = ProductUpload::where('product_id', '=', $id)
167
            ->select('id', 'product_id', 'title', 'description', 'version', 'file')
168
            ->get();
169
170
            return \DataTables::of($new_upload)
171
        ->addColumn('checkbox', function ($model) {
172
            return "<input type='checkbox' class='upload_checkbox' value=".$model->id.' name=select[] id=checks>';
173
        })
174
175
        ->addColumn('product_id', function ($model) {
176
            return ucfirst($this->product->where('id', $model->product_id)->first()->name);
177
        })
178
179
        ->addColumn('title', function ($model) {
180
            return ucfirst($model->title);
181
        })
182
        ->addColumn('description', function ($model) {
183
            return ucfirst($model->description);
184
        })
185
        ->addColumn('version', function ($model) {
186
            return $model->version;
187
        })
188
189
        ->addColumn('file', function ($model) {
190
            return $model->file;
191
        })
192
        ->addColumn('action', function ($model) {
193
            return '<a href='.('#edit-upload-option/'.$model->id).' 
194
             class=" btn btn-sm btn-primary " data-title="'.$model->title.'"
195
              data-description="'.$model->description.'" data-version="'
196
              .$model->version.'" data-id="'.$model->id.'" onclick="openEditPopup(this)" >Edit</a>';
197
        })
198
        ->rawcolumns(['checkbox', 'product_id', 'title', 'description', 'version', 'file', 'action'])
199
        ->make(true);
200
        }
201
202
        // Save file Info in Modal popup
203
        public function save(Request $request)
204
        {
205
            try {
206
                $product_id = Product::where('name', '=', $request->input('product'))->select('id')->first();
207
208
                $this->product_upload->product_id = $product_id->id;
209
                $this->product_upload->title = $request->input('title');
210
                $this->product_upload->description = $request->input('description');
211
                $this->product_upload->version = $request->input('version');
212
213
                if ($request->file) {
214
                    $file = $request->file('file')->getClientOriginalName();
215
216
                    $destination = storage_path().'/products';
217
                    $request->file('file')->move($destination, $file);
218
                    $this->product_upload->file = $file;
219
                }
220
                $this->product_upload->save();
221
222
                return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
223
            } catch (\Exception $e) {
224
                Bugsnag::notifyException($e);
225
226
                return redirect()->with('fails', $e->getMessage());
227
            }
228
        }
229
230
        //Update the File Info
231
        public function uploadUpdate($id, Request $request)
232
        {
233
            $file_upload = ProductUpload::find($id);
234
235
            $file_upload->title = $request->input('title');
236
            $file_upload->description = $request->input('description');
237
            $file_upload->version = $request->input('version');
238
            if ($request->file) {
239
                $file = $request->file('file')->getClientOriginalName();
240
241
                $destination = storage_path().'/products';
242
                $request->file('file')->move($destination, $file);
243
                $file_upload->file = $file;
244
            }
245
            $file_upload->save();
246
247
            return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
248
        }
249
250
        /**
251
         * Show the form for creating a new resource.
252
         *
253
         * @return \Response
254
         */
255
        public function create()
256
        {
257
            try {
258
                /*
259
                 * server url
260
                 */
261
                $url = $this->getMyUrl();
262
                $i = $this->product->orderBy('created_at', 'desc')->first()->id + 1;
263
                $cartUrl = $url.'/pricing?id='.$i;
264
                $type = $this->type->pluck('name', 'id')->toArray();
265
                $subscription = $this->plan->pluck('name', 'id')->toArray();
266
                $currency = $this->currency->pluck('name', 'code')->toArray();
267
                $group = $this->group->pluck('name', 'id')->toArray();
268
                $products = $this->product->pluck('name', 'id')->toArray();
269
                $periods = $this->period->pluck('name', 'days')->toArray();
270
                $taxes = $this->tax_class->pluck('name', 'id')->toArray();
271
272
                return view('themes.default1.product.product.create',
273
                    compact('subscription', 'type', 'periods', 'currency',
274
                        'group', 'cartUrl', 'products', 'taxes'));
275
            } catch (\Exception $e) {
276
                Bugsnag::notifyException($e);
277
278
                return redirect()->back()->with('fails', $e->getMessage());
279
            }
280
        }
281
282
        /**
283
         * Store a newly created resource in storage.
284
         *
285
         * @return \Response
286
         */
287
        public function store(Request $request)
288
        {
289
            $input = $request->all();
290
            // dd($input);
291
            $v = \Validator::make($input, [
292
                        'name'       => 'required|unique:products,name',
293
                        'type'       => 'required',
294
                        'group'      => 'required',
295
                        'description'=> 'required',
296
                        // 'image'   => 'sometimes | mimes:jpeg,jpg,png,gif | max:1000',
297
                        // 'version' => 'required',
298
            ]);
299
            if ($v->fails()) {
300
                //     $currency = $input['currency'];
301
302
                return redirect()->back()
303
                        ->withErrors($v)
304
                        ->withInput()
305
                        ->with('currency');
306
            }
307
308
            try {
309
                if ($request->hasFile('image')) {
310
                    $image = $request->file('image')->getClientOriginalName();
311
                    $imagedestinationPath = 'dist/product/images';
312
                    $request->file('image')->move($imagedestinationPath, $image);
313
                    $this->product->image = $image;
314
                }
315
316
                $product = $this->product;
317
                $product->fill($request->except('image', 'file'))->save();
318
                // Product::where('id',$product->id)->update(['name'=>$request->names]);
319
320
                $product_id = $product->id;
321
                $subscription = $request->input('subscription');
322
323
                $price = $request->input('price');
324
                // $price=
325
326
                $sales_price = $request->input('sales_price');
327
                $currencies = $request->input('currency');
328
                $taxes = $request->input('tax');
329
                if ($taxes) {
330
                    foreach ($taxes as $key=>$value) {
331
                        $newtax = new TaxProductRelation();
332
                        $newtax->product_id = $product_id;
333
                        $newtax->tax_class_id = $value;
334
                        $newtax->save();
335
                    }
336
                }
337
338
                return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
339
            } catch (\Exception $e) {
340
                Bugsnag::notifyException($e);
341
342
                return redirect()->with('fails', $e->getMessage());
343
            }
344
        }
345
346
        /**
347
         * Show the form for editing the specified resource.
348
         *
349
         * @param int $id
350
         *
351
         * @return \Response
352
         */
353
        public function edit($id)
354
        {
355
            try {
356
                $type = $this->type->pluck('name', 'id')->toArray();
357
358
                $subscription = $this->plan->pluck('name', 'id')->toArray();
359
                $currency = $this->currency->pluck('name', 'code')->toArray();
360
                $group = $this->group->pluck('name', 'id')->toArray();
361
                $products = $this->product->pluck('name', 'id')->toArray();
362
                $periods = $this->period->pluck('name', 'days')->toArray();
363
                $url = $this->GetMyUrl();
364
                $cartUrl = $url.'/cart?id='.$id;
365
                $product = $this->product->where('id', $id)->first();
366
                $taxes = $this->tax_class->pluck('name', 'id')->toArray();
367
                // dd($taxes);
368
                $saved_taxes = $this->tax_relation->where('product_id', $id)->get();
369
                $savedTaxes = $this->tax_relation->where('product_id', $id)->pluck('tax_class_id')->toArray();
370
371
                return view('themes.default1.product.product.edit',
372
                    compact('product', 'periods', 'type', 'subscription',
373
                        'currency', 'group', 'price', 'cartUrl', 'products',
374
                        'regular', 'sales', 'taxes', 'saved_taxes', 'savedTaxes'));
375
            } catch (\Exception $e) {
376
                Bugsnag::notifyException($e);
377
378
                return redirect()->back()->with('fails', $e->getMessage());
379
            }
380
        }
381
382
        /**
383
         * Update the specified resource in storage.
384
         *
385
         * @param int $id
386
         *
387
         * @return \Response
388
         */
389
        public function update($id, Request $request)
390
        {
391
            $input = $request->all();
392
            $v = \Validator::make($input, [
393
                        'name'    => 'required',
394
                        'type'    => 'required',
395
                        'group'   => 'required',
396
                        'image'   => 'sometimes | mimes:jpeg,jpg,png,gif | max:1000',
397
      ]);
398
399
            if ($v->fails()) {
400
                return redirect()->back()->with('errors', $v->errors());
401
            }
402
403
            try {
404
                $product = $this->product->where('id', $id)->first();
405
                if ($request->hasFile('image')) {
406
                    $image = $request->file('image')->getClientOriginalName();
407
                    $imagedestinationPath = 'dist/product/images';
408
                    $request->file('image')->move($imagedestinationPath, $image);
409
                    $product->image = $image;
410
                }
411
                if ($request->hasFile('file')) {
412
                    $file = $request->file('file')->getClientOriginalName();
413
                    $filedestinationPath = storage_path().'/products';
414
                    $request->file('file')->move($filedestinationPath, $file);
415
                    $product->file = $file;
416
                }
417
                $product->fill($request->except('image', 'file'))->save();
418
                $this->updateVersionFromGithub($product->id);
419
420
                $product_id = $product->id;
421
                $subscription = $request->input('subscription');
422
                $cost = $request->input('price');
423
                $sales_price = $request->input('sales_price');
424
                $currencies = $request->input('currency');
425
426
                //add tax class to tax_product_relation table
427
                $taxes = $request->input('tax');
428
                 $newTax = $this->saveTax($taxes, $product_id);
429
                return redirect()->back()->with('success', \Lang::get('message.updated-successfully'));
430
            } catch (\Exception $e) {
431
                Bugsnag::notifyException($e);
432
433
                return redirect()->back()->with('fails', $e->getMessage());
434
            }
435
        }
436
437
         public function saveTax($taxes, $product_id)
438
        {
439
            if ($taxes) {
440
441
                    $this->tax_relation->where('product_id', $product_id)->delete();
442
                    foreach ($taxes as $tax) {
443
                        $newTax = new TaxProductRelation();
444
                        $newTax->product_id = $product_id;
445
                        $newTax->tax_class_id = $tax;
446
                        $newTax->save();
447
                    }
448
                }
449
             return $newTax;
450
        }
451
452
        /**
453
         * Remove the specified resource from storage.
454
         *
455
         * @param int $id
456
         *
457
         * @return \Response
458
         */
459
        public function destroy(Request $request)
460
        {
461
            try {
462
                $ids = $request->input('select');
463
                if (!empty($ids)) {
464
                    foreach ($ids as $id) {
465
                        if ($id != 1) {
466
                            $product = $this->product->where('id', $id)->first();
467
                            if ($product) {
468
                                $product->delete();
469
                            } else {
470
                                echo "<div class='alert alert-danger alert-dismissable'>
471
                    <i class='fa fa-ban'></i>
472
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '.
473
                    /* @scrutinizer ignore-type */\Lang::get('message.failed').'
474
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
475
                        './* @scrutinizer ignore-type */\Lang::get('message.no-record').'
476
                </div>';
477
                                //echo \Lang::get('message.no-record') . '  [id=>' . $id . ']';
478
                            }
479
                            echo "<div class='alert alert-success alert-dismissable'>
480
                    <i class='fa fa-ban'></i>
481
                    <b>"./* @scrutinizer ignore-type */
482
                    \Lang::get('message.alert').'!</b> './* @scrutinizer ignore-type */ \Lang::get('message.success').'
483
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
484
                        './* @scrutinizer ignore-type */\Lang::get('message.deleted-successfully').'
485
                </div>';
486
                        } else {
487
                            echo "<div class='alert alert-danger alert-dismissable'>
488
                    <i class='fa fa-ban'></i>
489
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '.
490
                    /* @scrutinizer ignore-type */\Lang::get('message.failed').'
491
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
492
                        './* @scrutinizer ignore-type */ \Lang::get('message.can-not-delete-default').'
493
                </div>';
494
                        }
495
                    }
496
                } else {
497
                    echo "<div class='alert alert-danger alert-dismissable'>
498
                    <i class='fa fa-ban'></i>
499
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '.
500
                    /* @scrutinizer ignore-type */\Lang::get('message.failed').'
501
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
502
                        './* @scrutinizer ignore-type */\Lang::get('message.select-a-row').'
503
                </div>';
504
                    //echo \Lang::get('message.select-a-row');
505
                }
506
                $lastActivity = Activity::all()->last();
507
            } catch (\Exception $e) {
508
                echo "<div class='alert alert-danger alert-dismissable'>
509
                    <i class='fa fa-ban'></i>
510
                    <b>"./* @scrutinizer ignore-type */\Lang::get('message.alert').'!</b> '.
511
                    /* @scrutinizer ignore-type */\Lang::get('message.failed').'
512
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
513
                        '.$e->getMessage().'
514
                </div>';
515
            }
516
        }
517
518
        /**
519
         * Remove the specified resource from storage.
520
         *
521
         * @param int $id
522
         *
523
         * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Product\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
524
         */
525
        public function fileDestroy(Request $request)
526
        {
527
            try {
528
                $ids = $request->input('select');
529
                if (!empty($ids)) {
530
                    foreach ($ids as $id) {
531
                        if ($id != 1) {
532
                            $product = $this->product_upload->where('id', $id)->first();
533
                            if ($product) {
534
                                $product->delete();
535
                            } else {
536
                                echo "<div class='alert alert-danger alert-dismissable'>
537
                    <i class='fa fa-ban'></i>
538
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.failed').'
539
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
540
                        '.\Lang::get('message.no-record').'
541
                </div>';
542
                                //echo \Lang::get('message.no-record') . '  [id=>' . $id . ']';
543
                            }
544
                            echo "<div class='alert alert-success alert-dismissable'>
545
                    <i class='fa fa-ban'></i>
546
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.success').'
547
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
548
                        '.\Lang::get('message.deleted-successfully').'
549
                </div>';
550
                        } else {
551
                            echo "<div class='alert alert-danger alert-dismissable'>
552
                    <i class='fa fa-ban'></i>
553
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.failed').'
554
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
555
                        '.\Lang::get('message.can-not-delete-default').'
556
                </div>';
557
                        }
558
                    }
559
                } else {
560
                    echo "<div class='alert alert-danger alert-dismissable'>
561
                    <i class='fa fa-ban'></i>
562
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.failed').'
563
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
564
                        '.\Lang::get('message.select-a-row').'
565
                </div>';
566
                    //echo \Lang::get('message.select-a-row');
567
                }
568
            } catch (\Exception $e) {
569
                echo "<div class='alert alert-danger alert-dismissable'>
570
                    <i class='fa fa-ban'></i>
571
                    <b>".\Lang::get('message.alert').'!</b> '.\Lang::get('message.failed').'
572
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
573
                        '.$e->getMessage().'
574
                </div>';
575
            }
576
        }
577
578
      
579
        /*
580
        *  Download Files from Filesystem/Github
581
        */
582
        public function downloadProduct($uploadid, $id, $invoice_id, $version_id = '')
583
        {
584
            try {
585
                $product = $this->product->findOrFail($uploadid);
586
                $type = $product->type;
587
                $owner = $product->github_owner;
588
                $repository = $product->github_repository;
589
                $file = $this->product_upload
590
                ->where('product_id', '=', $uploadid)
591
                ->where('id', $version_id)->select('file')->first();
592
                $order = Order::where('invoice_id', '=', $invoice_id)->first();
593
                $order_id = $order->id;
594
                if ($type == 2) {
595
                    $relese = $this->getRelease($owner, $repository, $order_id, $file);
596
597
                    return $relese;
598
                }
599
            } catch (\Exception $e) {
600
                Bugsnag::notifyException($e);
601
602
                return redirect()->back()->with('fails', $e->getMessage());
603
            }
604
        }
605
606
        public function adminDownload($id, $invoice = '', $api = false)
607
        {
608
            try {
609
                $role = \Auth::user()->role;
610
                $release = $this->getLinkToDownload($role, $invoice, $id);
611
612
                if (is_array($release) && array_key_exists('type', $release)) {
613
                    header('Location: '.$release['release']);
614
                    exit;
615
                } else {
616
                    header('Content-type: Zip');
617
                    header('Content-Description: File Transfer');
618
                    header('Content-Disposition: attachment; filename=Faveo.zip');
619
                    header('Content-Length: '.filesize($release));
620
                    flush();
621
                    readfile("$release");
622
                }
623
            } catch (\Exception $e) {
624
                if ($api) {
625
                    return response()->json(['error'=>$e->getMessage()]);
626
                }
627
                Bugsnag::notifyException($e);
628
629
                return redirect()->back()->with('fails', $e->getMessage());
630
            }
631
        }
632
633
        public function getProductField($productid)
634
        {
635
            try {
636
                $field = '';
637
                $product = $this->product->find($productid);
638
                if ($product) {
639
                    if ($product->require_domain == 1) {
640
                        $field .= "<div class='col-md-4 form-group'>
641
                            <label class='required'>"./* @scrutinizer ignore-type */
642
                             \Lang::get('message.domain')."</label>
643
                            <input type='text' name='domain' class='form-control' 
644
                            id='domain' placeholder='http://example.com'>
645
                    </div>";
646
                    }
647
                }
648
649
                return $field;
650
            } catch (\Exception $ex) {
651
                Bugsnag::notifyException($ex);
652
653
                return $ex->getMessage();
654
            }
655
        }
656
657
        public function getSubscriptionCheckScript()
658
        {
659
            $response = "<script>
660
        function getPrice(val) {
661
            var user = document.getElementsByName('user')[0].value;
662
            var plan = '';
663
            if ($('#plan').length > 0) {
664
                var plan = document.getElementsByName('plan')[0].value;
665
            }
666
            //var plan = document.getElementsByName('plan')[0].value;
667
            //alert(user);
668
669
            $.ajax({
670
                type: 'POST',
671
                url: ".url('get-price').",
672
                data: {'product': val, 'user': user,'plan':plan},
673
                //data: 'product=' + val+'user='+user,
674
                success: function (data) {
675
                    var price = data['price'];
676
                    var field = data['field'];
677
                    $('#price').val(price);
678
                    $('#fields').append(field);
679
                }
680
            });
681
        }
682
683
    </script>";
684
        }
685
    }
686