forked from eeukolov/r-keeper_cost_loader_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrk7.php
71 lines (59 loc) · 2.17 KB
/
rk7.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require_once '_config.php';
require_once 'logger.php';
function postCURL_RK7($payload)
{
logger('Отправляем запрос к API RK7');
$ch = curl_init(RK7_API_URL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, RK7_API_USER . ':' . RK7_API_PASSWORD);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: text/xml')
);
$result = curl_exec($ch);
$curl_error = curl_error($ch);
curl_close($ch);
if ($result === false) {
$error = "Ошибка запроса к RK7 Api: " . $curl_error;
logger($error);
exit;
}
return new SimpleXMLElement($result);
}
function get_menu()
{
logger('Получаем меню RK7');
$cmd = '<?xml version="1.0" encoding="UTF-8"?>
<RK7Query>
<RK7Command CMD="GetRefData" RefName="MenuItems" WithMacroProp ="1" WithChildItems="0" IgnoreDefaults="1"></RK7Command>
</RK7Query>
';
$result = postCURL_RK7($cmd);
$menu = [];
if (isset($result->CommandResult->RK7Reference->Items)) {
foreach ($result->CommandResult->RK7Reference->Items->Item as $item) {
$cur = current($item);
if ($cur['GUIDString'] !== '' and $cur['SaleObjectType'] === 'sotMenuItem' and isset($cur['CLASSIFICATORGROUPS-' . RK7_CLASSIFICATION_ID]) and $cur['CLASSIFICATORGROUPS-' . RK7_CLASSIFICATION_ID] != 0) {
$menu[] = array(
'name' => $cur['Name'],
'guid' => $cur['GUIDString'],
'categ' => $cur['CLASSIFICATORGROUPS-' . RK7_CLASSIFICATION_ID]
);
}
}
return $menu;
}
}
function formatXml($simpleXMLElement)
{
$xmlDocument = new DOMDocument('1.0');
$xmlDocument->preserveWhiteSpace = false;
$xmlDocument->formatOutput = true;
$xmlDocument->loadXML($simpleXMLElement->asXML());
return $xmlDocument->saveXML();
}