-
Notifications
You must be signed in to change notification settings - Fork 0
/
category.php
52 lines (38 loc) · 1.4 KB
/
category.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php declare(strict_types=1);
// required headers
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=UTF-8');
// database connection will be here
require_once 'bootstrap.php';
require_once 'category_helper.php';
$ids = (array) $_GET['id'] ?: [];
// $ids is empty: read all ids
if (!(bool) count($ids)) {
/** @var \Doctrine\DBAL\Query\QueryBuilder $queryBuilder */
$container = \OxidEsales\EshopCommunity\Internal\Container\ContainerFactory::getInstance()->getContainer();
$queryBuilderFactory = $container->get(\OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface::class);
$queryBuilder = $queryBuilderFactory->create();
$result = $queryBuilder->select('*')->from('oxcategories')->execute()->fetchAll();
foreach ($result as $key => $category) {
$ids[] = $category['OXID'];
}
}
$categories = [];
foreach ($ids as $id) {
$category = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
if ($category->load($id)) {
removePreLoadedProperties($category);
loadFlagshipProperties($category);
$categories[] = $category;
}
}
if ((bool) count($categories)) {
displayResult($categories);
} else {
// set response code - 404 Not found
http_response_code(404);
// tell the user no products found
echo json_encode(
['message' => 'No category found.']
);
}