Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
results.php
1<?php
2
4
8
9class Results extends DataProcessor
10{
11 protected $siteId;
12
13 public function __construct($params)
14 {
15 if(!isset($params["SITE_ID"]) || $params["SITE_ID"] == '')
16 throw new ArgumentNullException("SITE_ID");
17
18 $this->siteId = $params["SITE_ID"];
19 }
20
21 public function process($data)
22 {
23 if(!isset($data["RESULT_ID"]))
24 throw new ArgumentNullException("data[\"RESULT_ID\"]");
25
26 if(isset($data["XML"]))
27 {
28 $fields["RESULTS"] = $data["XML"];
29 \Bitrix\Sale\TradingPlatform\Ebay\Feed\ResultsTable::update($data["RESULT_ID"], $fields);
30 }
31
32 $message = "";
33
34 if(isset($data["ARRAY"]["RequestDetails"]["Errors"]["Error"]))
35 $message .= $this->getErrorsString($data["ARRAY"]["RequestDetails"]["Errors"]["Error"]);
36
37 if(isset($data["ARRAY"]["RequestDetails"]["Warnings"]["Warning"]))
38 $message .= $this->getWarningsString($data["ARRAY"]["RequestDetails"]["Warnings"]["Warning"]);
39
40 if(isset($data["ARRAY"]["ProductResult"]))
41 $message .= $this->getProductsString($data["ARRAY"]["ProductResult"]);
42
43 if($message <> '')
44 {
45 if(mb_strtolower(SITE_CHARSET) != 'utf-8')
46 $message = \Bitrix\Main\Text\Encoding::convertEncoding($message, 'UTF-8', SITE_CHARSET);
47
48 $message = "RequestId: ".$data["ARRAY"]["RequestDetails"]["RequestID"]."\n".
49 "StartTime: ".$data["ARRAY"]["RequestDetails"]["StartTime"]."\n".
50 "EndTime: ".$data["ARRAY"]["RequestDetails"]["EndTime"]."\n\n".
51 $message;
52
55 "EBAY_FEED_RESULTS_ERROR",
56 $data["ARRAY"]["RequestDetails"]["RequestID"],
57 $message,
58 $this->siteId);
59 }
60
61 return true;
62 }
63
64 protected function getProductsString($products)
65 {
66 if(!is_array($products) || empty($products))
67 return "";
68
69 reset($products);
70
71 if(key($products) !== 0)
72 $products = array( 0 => $products);
73
74 $result = "";
75
76 foreach($products as $product)
77 $result .= $this->getProductInfo($product);
78
79 return $result;
80 }
81
82 protected function getProductInfo($product)
83 {
84 if(!is_array($product) || empty($product))
85 return "";
86
87 $result = "";
88
89 if(isset($product["Errors"]["Error"]) || isset($product["Warnings"]["Warning"]))
90 {
91 if(isset($product["ProductID"]))
92 $result .= "\nProductID: ".$product["ProductID"]."\n";
93
94 if(isset($product["Result"]))
95 $result .= "Result: ".$product["Result"]."\n";
96
97 if(isset($product["Action"]))
98 $result .= "Action: ".$product["Action"]."\n";
99 }
100
101 if(isset($product["Errors"]["Error"]))
102 $result .= $this->getErrorsString($product["Errors"]["Error"]);
103
104 if(isset($product["Warnings"]["Warning"]))
105 $result .= $this->getWarningsString($product["Warnings"]["Warning"]);
106
107 return $result;
108 }
109
110 protected function getErrorsString($errors)
111 {
112 if(!is_array($errors) || empty($errors))
113 return "";
114
115 reset($errors);
116
117 if(key($errors) !== 0)
118 $errors = array( 0 => $errors);
119
120 $result = "";
121
122 foreach($errors as $error)
123 $result .= "Error: ".$error["Message"]." (error code: ".$error["Code"].").\n";
124
125 return $result;
126 }
127
128 protected function getWarningsString($warnings)
129 {
130 if(!is_array($warnings) || empty($warnings))
131 return "";
132
133 reset($warnings);
134
135 if(key($warnings) !== 0)
136 $warnings = array( 0 => $warnings);
137
138 $result = "";
139
140 foreach($warnings as $warning)
141 $result .= "Warning: ".$warning["Message"]." (warning code: ".$warning["Code"].").\n";
142
143 return $result;
144 }
145}
static log($level, $type, $itemId, $description, $siteId)
Definition ebay.php:147