Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
statistics.php
1<?php
2
3
5
6
14
16 implements IProxy
17{
18
19 protected $collection;
20
24 public function getCollection(): Collection
25 {
26 return $this->collection;
27 }
28
29 public function __construct()
30 {
31 $this->collection = new Collection();
32 }
33 public function init($params)
34 {
35 foreach($params as $index=>$item)
36 {
37 $this->collection->addItem(
38 Item::create(
39 (new Order())
40 ->setEntityId($index)
41 ->setEntityTypeId(EntityType::ORDER)
42 ->setDateUpdate($item['dateUpdate'])
43 ->setCurrency($item['currency'])
44 ->setProviderId($item['providerId'])
45 ->setStatus($item['status'])
46 ->setXmlId($item['xmlId'])
47 ->setAmount($item['amount']))
48 ->setInternalIndex($index)
49 );
50 }
51
52 return $this;
53 }
54
55 static public function getProxy()
56 {
57 return new \Bitrix\Sale\Exchange\Integration\Rest\RemoteProxies\Sale\Statistics();
58 }
59
63 public function modify()
64 {
67 foreach ($this->getCollection() as $item)
68 {
69 $providerId = $item->getEntity()->getProviderId();
70 break;
71 }
72
73 return $this
74 ->modifyFromParams([
75 'provider'=>['id'=>$providerId],
76 'statistics'=>$this
78 ->toArray()
79 ]);
80 }
81
82 static protected function proxyModify(array $list)
83 {
84 $proxy = static::getProxy();
85 $r = $proxy->modify($list);
86 if($r->isSuccess())
87 {
88 $result = $r->getData()['DATA']['result'];
89 }
90 else
91 {
92 $result['error'] = $r->getErrorMessages();
93 }
94
95 return $result;
96 }
97
102 protected function modifyFromParams(array $params)
103 {
104 $r = new Result();
105
106 $res = static::proxyModify($params);
107
108 if (!empty($res['error']))
109 {
110 foreach ($res['error'] as $error)
111 {
112 $r->addError(new Error($error));
113 }
114 }
115
116 return $r;
117 }
118
119}