Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
controllerbase.php
1<?php
2
3
5
13
14class ControllerBase extends Base
15{
16 protected function createViewManager(Action $action)
17 {
18 return new SaleViewManager($action);
19 }
20
21 protected static function getNavData($start, $orm = false)
22 {
23 if($start >= 0)
24 {
25 return ($orm ?
26 ['limit' => \IRestService::LIST_LIMIT, 'offset' => intval($start)]
27 :['nPageSize' => \IRestService::LIST_LIMIT, 'iNumPage' => intval($start / \IRestService::LIST_LIMIT) + 1]
28 );
29 }
30 else
31 {
32 return ($orm ?
33 ['limit' => \IRestService::LIST_LIMIT]
34 :['nTopCount' => \IRestService::LIST_LIMIT]
35 );
36 }
37 }
38
39 protected static function getApplication()
40 {
42 global $APPLICATION;
43
44 return $APPLICATION;
45 }
46
47 protected function isCrmModuleInstalled()
48 {
49 return ModuleManager::isModuleInstalled('crm');
50 }
51
52 public function getBuilder(SettingsContainer $settings=null)
53 {
54 $settings = $settings === null? $this->getSettingsContainerDefault():$settings;
55
56 return ($this->isCrmModuleInstalled() && Loader::includeModule('crm'))
57 ? new \Bitrix\Crm\Order\Builder\OrderBuilderRest($settings)
58 : new \Bitrix\Sale\Helpers\Order\Builder\OrderBuilderRest($settings);
59 }
60
61 protected function getSettingsContainerDefault()
62 {
63 return new SettingsContainer([
64 'deleteClientsIfNotExists' => true,
65 'deleteTradeBindingIfNotExists' => true,
66 'deletePaymentIfNotExists' => true,
67 'deleteShipmentIfNotExists' => true,
68 'deleteShipmentItemIfNotExists' => true,
69 'deletePropertyValuesIfNotExists' => true,
70 'createDefaultPaymentIfNeed' => false,
71 'createDefaultShipmentIfNeed' => false,
72 'createUserIfNeed' => false,
73 'cacheProductProviderData' => false,
74 'propsFiles' => $this->getFielsPropertyValuesFromRequest(),
75 'acceptableErrorCodes' => []
76 ]);
77 }
78
80 {
81 $orderProperties = [];
82
83 if(isset($this->request->getFileList()['fields']['PROPERTIES']))
84 {
85 foreach ($this->request->getFileList()['fields']['PROPERTIES'] as $orderPropId => $arFileData)
86 {
87 if (is_array($arFileData))
88 {
89 foreach ($arFileData as $param_name => $value)
90 {
91 if (is_array($value))
92 {
93 foreach ($value as $nIndex => $val)
94 {
95 if ($arFileData["name"][$nIndex] <> '')
96 $orderProperties[$orderPropId][$nIndex][$param_name] = $val;
97 }
98 }
99 else
100 $orderProperties[$orderPropId][$param_name] = $value;
101 }
102 }
103 }
104 }
105 return $orderProperties;
106 }
107
108 protected function toArray(\Bitrix\Sale\Order $order, array $fields=[])
109 {
110 // , ,
111 $fields = array_merge($fields, $this->getAdditionalFields($order));
112
113 if($this->isCrmModuleInstalled() && Loader::includeModule('crm'))
114 {
115 $director = new \Bitrix\Crm\Order\Rest\Normalizer\Director();
116 $normalizer = new \Bitrix\Crm\Order\Rest\Normalizer\ObjectNormalizer($fields);
117 }
118 else
119 {
120 $director = new \Bitrix\Sale\Rest\Normalizer\Director();
121 $normalizer = new \Bitrix\Sale\Rest\Normalizer\ObjectNormalizer($fields);
122 }
123
124 return $director->normalize($normalizer, $order);
125 }
126
127 private function getAdditionalFields(\Bitrix\Sale\Order $order)
128 {
129 $ixInternal = [];
130 //region fill internal Index
131 foreach(\Bitrix\Sale\PersonType::getList(['select'=>['ID', 'XML_ID']]) as $row)
132 $ixInternal['personType'][$row['ID']] = $row['XML_ID'];
133
134 foreach(\Bitrix\Sale\OrderStatus::getList(['select'=>['ID', 'XML_ID']]) as $row)
135 $ixInternal['orderStatus'][$row['ID']] = $row['XML_ID'];
136
137 foreach(\Bitrix\Sale\Property::getList(['select'=>['ID', 'XML_ID']])->fetchAll() as $row)
138 $ixInternal['properties'][$row['ID']] = $row['XML_ID'];
139
140 foreach(\Bitrix\Sale\PaySystem\Manager::getList(['select'=>['ID', 'XML_ID', 'IS_CASH']])->fetchAll() as $row)
141 {
142 $ixInternal['paySystems'][$row['ID']]['XML_ID'] = $row['XML_ID'];
143 $ixInternal['paySystems'][$row['ID']]['IS_CASH'] = $row['IS_CASH'];
144 }
145
146 foreach(\Bitrix\Sale\Delivery\Services\Manager::getActiveList() as $row)
147 $ixInternal['deliverySystems'][$row['ID']] = $row['XML_ID'];
148
149 foreach(\Bitrix\Sale\DeliveryStatus::getList(['select'=>['ID', 'XML_ID']]) as $row)
150 $ixInternal['deliveryStatus'][$row['ID']] = $row['XML_ID'];
151
152 foreach(\Bitrix\Sale\TradingPlatformTable::getList(['select'=>['ID', 'XML_ID']])->fetchAll() as $row)
153 $ixInternal['tradingPlatform'][$row['ID']] = $row['XML_ID'];
154 //endregion
155
156 $r['ORDER'][$order->getInternalId()] = [
157 'PERSON_TYPE_XML_ID'=>$ixInternal['personType'][$order->getPersonTypeId()],
158 'STATUS_XML_ID'=>$ixInternal['orderStatus'][$order->getField('STATUS_ID')]];
159
160 foreach ($order->getPropertyCollection() as $property)
161 $r['PROPERTIES'][$property->getInternalIndex()] = ['ORDER_PROPS_XML_ID'=>$ixInternal['properties'][$property->getPropertyId()]];
162
163 foreach ($order->getPaymentCollection() as $payment)
164 $r['PAYMENTS'][$payment->getInternalIndex()] = [
165 'PAY_SYSTEM_XML_ID'=>$ixInternal['paySystems'][$payment->getPaymentSystemId()]['XML_ID'],
166 'PAY_SYSTEM_IS_CASH'=>$ixInternal['paySystems'][$payment->getPaymentSystemId()]['IS_CASH']
167 ];
168
170 foreach ($order->getShipmentCollection() as $shipment)
171 {
172 $shipmentIndex = $shipment->getInternalIndex();
173 $r['SHIPMENTS'][$shipmentIndex] = [
174 'DELIVERY_XML_ID'=>$ixInternal['deliverySystems'][$shipment->getDeliveryId()],
175 'STATUS_XML_ID'=>$ixInternal['deliveryStatus'][$shipment->getField('STATUS_ID')]];
176 }
177
179 foreach ($order->getTradeBindingCollection() as $binding)
180 if($binding->getTradePlatform() !== null)
181 $r['TRADE_BINDINGS'][$binding->getInternalIndex()] = ['TRADING_PLATFORM_XML_ID'=>$ixInternal['tradingPlatform'][$binding->getTradePlatform()->getId()]];
182
183 return $r;
184 }
185}
toArray(\Bitrix\Sale\Order $order, array $fields=[])
getBuilder(SettingsContainer $settings=null)
static getNavData($start, $orm=false)
static getList(array $parameters=[])
static getList(array $parameters=[])
static getList(array $parameters=array())