|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\MagentoBundle\Utils; |
|
4
|
|
|
|
|
5
|
|
|
class WSIUtils |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Do modifications with response for collection requests |
|
9
|
|
|
* Fix issues related to specific results in WSI mode |
|
10
|
|
|
* |
|
11
|
|
|
* @param mixed $response |
|
12
|
|
|
* |
|
13
|
|
|
* @return array |
|
14
|
|
|
*/ |
|
15
|
|
|
public static function processCollectionResponse($response) |
|
16
|
|
|
{ |
|
17
|
|
|
if (!is_array($response)) { |
|
18
|
|
|
if ($response && is_object($response)) { |
|
19
|
|
|
// response is object, but might be empty in case when no data in WSI mode |
|
20
|
|
|
$data = get_object_vars($response); |
|
21
|
|
|
if (empty($data)) { |
|
22
|
|
|
$response = []; |
|
23
|
|
|
} else { |
|
24
|
|
|
// single result in WSI mode |
|
25
|
|
|
$response = [$response]; |
|
26
|
|
|
} |
|
27
|
|
|
} else { |
|
28
|
|
|
// for empty results in Soap V2 |
|
29
|
|
|
$response = []; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
return $response; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param array $response |
|
38
|
|
|
* @return array |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function convertResponseToMultiArray($response) |
|
41
|
|
|
{ |
|
42
|
|
|
if (is_array($response) && array_key_exists(0, $response) === false && count($response) > 0) { |
|
43
|
|
|
return [$response]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $response; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Parse WSI response and nested data |
|
51
|
|
|
* |
|
52
|
|
|
* @param mixed $result |
|
53
|
|
|
* @param bool $defaultNull if not found in result node return null |
|
54
|
|
|
* |
|
55
|
|
|
* @return null |
|
56
|
|
|
*/ |
|
57
|
|
|
public static function parseWSIResponse($result, $defaultNull = true) |
|
58
|
|
|
{ |
|
59
|
|
|
if (is_object($result)) { |
|
60
|
|
|
if (!empty($result->result)) { |
|
61
|
|
|
$result = $result->result; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (isset($result->complexObjectArray)) { |
|
65
|
|
|
$result = $result->complexObjectArray; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$objectArray = is_array($result) ? $result : [$result]; |
|
69
|
|
|
foreach ($objectArray as $singleObject) { |
|
70
|
|
|
if (is_object($singleObject)) { |
|
71
|
|
|
$vars = get_object_vars($singleObject); |
|
72
|
|
|
|
|
73
|
|
|
foreach ($vars as $var => $value) { |
|
74
|
|
|
$singleObject->$var = self::parseWSIResponse($singleObject->$var, false); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} elseif ($defaultNull) { |
|
79
|
|
|
$result = null; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $result; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|