|
1
|
|
|
<?php namespace Bedard\Shop\Api; |
|
2
|
|
|
|
|
3
|
|
|
use Bedard\Shop\Classes\ApiController; |
|
4
|
|
|
use Bedard\Shop\Repositories\CartRepository; |
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Log; |
|
7
|
|
|
|
|
8
|
|
|
class Cart extends ApiController |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Add an inventory to the cart. |
|
12
|
|
|
* |
|
13
|
|
|
* @param CartRepository $repository |
|
14
|
|
|
*/ |
|
15
|
|
|
public function add(CartRepository $repository) |
|
16
|
|
|
{ |
|
17
|
|
|
try { |
|
|
|
|
|
|
18
|
|
|
// @todo |
|
19
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
20
|
|
|
Log::error($e->getMessage()); |
|
21
|
|
|
|
|
22
|
|
|
abort(500, $e->getMessage()); |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Determine if a cart exists or not. |
|
28
|
|
|
* |
|
29
|
|
|
* @param CartRepository $repository |
|
30
|
|
|
* @return bool |
|
31
|
|
|
*/ |
|
32
|
|
|
public function exists(CartRepository $repository) |
|
33
|
|
|
{ |
|
34
|
|
|
try { |
|
35
|
|
|
return $repository->exists() ? 'true' : 'false'; |
|
36
|
|
|
} catch (Exception $e) { |
|
37
|
|
|
Log::error($e->getMessage()); |
|
38
|
|
|
|
|
39
|
|
|
abort(500, $e->getMessage()); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Show the current cart. |
|
45
|
|
|
* |
|
46
|
|
|
* @param \Bedard\Shop\Repositories\CartRepository $repository |
|
47
|
|
|
* @return \Bedard\Shop\Models\Cart |
|
48
|
|
|
*/ |
|
49
|
|
|
public function index(CartRepository $repository) |
|
50
|
|
|
{ |
|
51
|
|
|
try { |
|
52
|
|
|
return $repository->loadCart(); |
|
53
|
|
|
} catch (Exception $e) { |
|
54
|
|
|
Log::error($e->getMessage()); |
|
55
|
|
|
|
|
56
|
|
|
abort(500, $e->getMessage()); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Create a new cart. |
|
62
|
|
|
* |
|
63
|
|
|
* @param \Bedard\Shop\Repositories\CartRepository $repository |
|
64
|
|
|
* @return \Bedard\Shop\Models\Cart |
|
65
|
|
|
*/ |
|
66
|
|
|
public function store(CartRepository $repository) |
|
67
|
|
|
{ |
|
68
|
|
|
try { |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
// @todo |
|
71
|
|
|
} catch (Exception $e) { |
|
|
|
|
|
|
72
|
|
|
Log::error($e->getMessage()); |
|
73
|
|
|
|
|
74
|
|
|
abort(500, $e->getMessage()); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check looks for
tryblocks that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.If there is nothing in the
trythen thecatchblock can never be executed either. Thus, thesetrystatements can be removed completely.