|
1
|
|
|
<?php namespace Bedard\Shop\Api; |
|
2
|
|
|
|
|
3
|
|
|
use Bedard\Shop\Classes\ApiController; |
|
4
|
|
|
use Bedard\Shop\Models\ApiSettings; |
|
5
|
|
|
use Bedard\Shop\Repositories\CategoryRepository; |
|
6
|
|
|
use Exception; |
|
7
|
|
|
use Log; |
|
8
|
|
|
|
|
9
|
|
|
class Categories extends ApiController |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* List all categories. |
|
13
|
|
|
* |
|
14
|
|
|
* @return \October\Rain\Database\Collection |
|
15
|
|
|
*/ |
|
16
|
|
|
public function index(CategoryRepository $repository) |
|
17
|
|
|
{ |
|
18
|
|
|
try { |
|
19
|
|
|
$params = [ |
|
20
|
|
|
'hide_empty' => ApiSettings::categoriesHideEmpty(), |
|
21
|
|
|
'load_thumbnails' => ApiSettings::categoriesLoadThumbnails(), |
|
22
|
|
|
'select' => ApiSettings::categoriesSelect(), |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
return $repository->get($params); |
|
26
|
|
|
} catch (Exception $e) { |
|
27
|
|
|
Log::error($e->getMessage()); |
|
28
|
|
|
|
|
29
|
|
|
abort(500, $e->getMessage()); |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Find a single category. |
|
35
|
|
|
* |
|
36
|
|
|
* @param \Bedard\Shop\Repositories\CategoryRepository $repository |
|
37
|
|
|
* @param string $slug |
|
38
|
|
|
* @return \Bedard\Shop\Models\Category |
|
39
|
|
|
*/ |
|
40
|
|
|
public function show(CategoryRepository $repository, $slug) |
|
41
|
|
|
{ |
|
42
|
|
|
try { |
|
43
|
|
|
$params = [ |
|
44
|
|
|
'load_products' => ApiSettings::categoryLoadProducts(), |
|
45
|
|
|
'load_products_thumbnails' => ApiSettings::categoryLoadProductsThumbnails(), |
|
46
|
|
|
'load_thumbnails' => ApiSettings::categoryLoadThumbnails(), |
|
47
|
|
|
'products_select' => ApiSettings::categoryProductsSelect(), |
|
48
|
|
|
'select' => ApiSettings::categorySelect(), |
|
49
|
|
|
]; |
|
50
|
|
|
|
|
51
|
|
|
return $repository->show($slug, $params); |
|
52
|
|
|
} catch (Exception $e) { |
|
53
|
|
|
Log::error($e->getMessage()); |
|
54
|
|
|
|
|
55
|
|
|
abort(500, $e->getMessage()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|