-
Notifications
You must be signed in to change notification settings - Fork 0
/
order-state-callback.php
52 lines (44 loc) · 1.53 KB
/
order-state-callback.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
52
<?php
/**
* 2023 Servantes.
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author Pavel Vejnar <vejnar.p@gmail.com>
* @copyright 2022 - 2023 Servantes
* @license LICENSE.txt
*/
/*
tato stránka slouží jako API, pro automatickou změnu stavů v PS
*/
require_once __DIR__ . '/../../config/config.inc.php';
require_once __DIR__ . '/miguel.php';
use Miguel\Utils\MiguelApiError;
use Miguel\Utils\MiguelApiResponse;
// required thing for PrestaShop validator (needs to be after config.inc.php)
if (!defined('_PS_VERSION_')) {
exit;
}
header('Content-Type: application/json; charset=UTF-8');
$module = Miguel::createInstance();
$context = Context::getContext();
$context->controller = new FrontController();
$valid = $module->validateApiAccess();
if ($valid !== true) {
echo json_encode($valid, JSON_PRETTY_PRINT);
} else {
$json = $module->readFileContent('php://input');
$data = json_decode($json, true);
if (null === $data) {
$output = MiguelApiResponse::error(MiguelApiError::invalidPayload('payload is required'));
} elseif (false == array_key_exists('code', $data)) {
$output = MiguelApiResponse::error(MiguelApiError::invalidPayload('code not set'));
} else {
$output = MiguelApiResponse::success($module->setOrderStates($data), 'result');
}
echo json_encode($output);
}