28 return ModuleManager::isModuleInstalled(
'crm');
33 $r = $this->checkPermission($action->getName());
38 $internalizer = \Bitrix\Crm\Order\Rest\Internalizer::buildByAction($action, [], $this->
getScope());
42 $internalizer = \Bitrix\Sale\Rest\Internalizer::buildByAction($action, [], $this->
getScope());
45 $r = $internalizer->process();
49 $action->setArguments($r->getData()[
'data']);
50 return parent::processBeforeAction($action);
68 if($this->errorCollection->count()==0)
73 [$result->getId()=>$result->getItems()]:$result;
77 $externalizer = \Bitrix\Crm\Order\Rest\Externalizer::buildByAction($action, $data, $this->
getScope());
81 $externalizer = \Bitrix\Sale\Rest\Externalizer::buildByAction($action, $data, $this->
getScope());
87 return parent::processAfterAction($action, $result);
98 $externalizer->setFormat([
99 ModificationFieldsBase::TO_WHITE_LIST,
100 ModificationFieldsBase::SORTING_KEYS
107 $externalizer->getPage($result):$externalizer;
111 return $externalizer->
toArray();
115 return parent::processAfterAction($action, $result);
131 [
'limit' => \IRestService::LIST_LIMIT,
'offset' => intval($start)]
132 :[
'nPageSize' => \IRestService::LIST_LIMIT,
'iNumPage' => intval($start / \IRestService::LIST_LIMIT) + 1]
138 [
'limit' => \IRestService::LIST_LIMIT]
139 :[
'nTopCount' => \IRestService::LIST_LIMIT]
149 ? new \Bitrix\Crm\Order\Builder\OrderBuilderRest($settings)
150 : new \Bitrix\Sale\Helpers\Order\Builder\OrderBuilderRest($settings);
156 'deleteClientsIfNotExists' =>
true,
157 'deleteTradeBindingIfNotExists' =>
true,
158 'deletePaymentIfNotExists' =>
true,
159 'deleteShipmentIfNotExists' =>
true,
160 'deleteShipmentItemIfNotExists' =>
true,
161 'deletePropertyValuesIfNotExists' =>
true,
162 'createDefaultPaymentIfNeed' =>
false,
163 'createDefaultShipmentIfNeed' =>
false,
164 'createUserIfNeed' => SettingsContainer::SET_ANONYMOUS_USER,
165 'cacheProductProviderData' =>
false,
167 'acceptableErrorCodes' => []
173 $orderProperties = [];
175 if(isset($this->request->getFileList()[
'fields'][
'PROPERTIES']))
177 foreach ($this->request->getFileList()[
'fields'][
'PROPERTIES'] as $orderPropId => $arFileData)
179 if (is_array($arFileData))
181 foreach ($arFileData as $param_name => $value)
183 if (is_array($value))
185 foreach ($value as $nIndex => $val)
187 if ($arFileData[
"name"][$nIndex] <>
'')
188 $orderProperties[$orderPropId][$nIndex][$param_name] = $val;
192 $orderProperties[$orderPropId][$param_name] = $value;
197 return $orderProperties;
203 $fields = array_merge($fields, $this->getAdditionalFields($order));
207 $director = new \Bitrix\Crm\Order\Rest\Normalizer\Director();
208 $normalizer = new \Bitrix\Crm\Order\Rest\Normalizer\ObjectNormalizer($fields);
212 $director = new \Bitrix\Sale\Rest\Normalizer\Director();
213 $normalizer = new \Bitrix\Sale\Rest\Normalizer\ObjectNormalizer($fields);
216 return $director->normalize($normalizer, $order);
224 $ixInternal[
'personType'][$row[
'ID']] = $row[
'XML_ID'];
226 foreach(\
Bitrix\
Sale\OrderStatus::getList([
'select'=>[
'ID',
'XML_ID']]) as $row)
227 $ixInternal[
'orderStatus'][$row[
'ID']] = $row[
'XML_ID'];
229 foreach(\
Bitrix\
Sale\Property::getList([
'select'=>[
'ID',
'XML_ID']])->fetchAll() as $row)
230 $ixInternal[
'properties'][$row[
'ID']] = $row[
'XML_ID'];
232 foreach(\
Bitrix\
Sale\PaySystem\Manager::getList([
'select'=>[
'ID',
'XML_ID',
'IS_CASH']])->fetchAll() as $row)
234 $ixInternal[
'paySystems'][$row[
'ID']][
'XML_ID'] = $row[
'XML_ID'];
235 $ixInternal[
'paySystems'][$row[
'ID']][
'IS_CASH'] = $row[
'IS_CASH'];
239 $ixInternal[
'deliverySystems'][$row[
'ID']] = $row[
'XML_ID'];
241 foreach(\
Bitrix\
Sale\DeliveryStatus::getList([
'select'=>[
'ID',
'XML_ID']]) as $row)
242 $ixInternal[
'deliveryStatus'][$row[
'ID']] = $row[
'XML_ID'];
244 foreach(\
Bitrix\
Sale\TradingPlatformTable::getList([
'select'=>[
'ID',
'XML_ID']])->fetchAll() as $row)
245 $ixInternal[
'tradingPlatform'][$row[
'ID']] = $row[
'XML_ID'];
248 $r[
'ORDER'][$order->getInternalId()] = [
249 'PERSON_TYPE_XML_ID'=>$ixInternal[
'personType'][$order->getPersonTypeId()],
250 'STATUS_XML_ID'=>$ixInternal[
'orderStatus'][$order->getField(
'STATUS_ID')]];
252 foreach ($order->getPropertyCollection() as $property)
253 $r[
'PROPERTIES'][$property->getInternalIndex()] = [
'ORDER_PROPS_XML_ID'=>$ixInternal[
'properties'][$property->getPropertyId()]];
255 foreach ($order->getPaymentCollection() as $payment)
256 $r[
'PAYMENTS'][$payment->getInternalIndex()] = [
257 'PAY_SYSTEM_XML_ID'=>$ixInternal[
'paySystems'][$payment->getPaymentSystemId()][
'XML_ID'],
258 'PAY_SYSTEM_IS_CASH'=>$ixInternal[
'paySystems'][$payment->getPaymentSystemId()][
'IS_CASH']
262 foreach ($order->getShipmentCollection() as $shipment)
264 $shipmentIndex = $shipment->getInternalIndex();
265 $r[
'SHIPMENTS'][$shipmentIndex] = [
266 'DELIVERY_XML_ID'=>$ixInternal[
'deliverySystems'][$shipment->getDeliveryId()],
267 'STATUS_XML_ID'=>$ixInternal[
'deliveryStatus'][$shipment->getField(
'STATUS_ID')]];
271 foreach ($order->getTradeBindingCollection() as $binding)
272 if($binding->getTradePlatform() !==
null)
273 $r[
'TRADE_BINDINGS'][$binding->getInternalIndex()] = [
'TRADING_PLATFORM_XML_ID'=>$ixInternal[
'tradingPlatform'][$binding->getTradePlatform()->getId()]];
278 private function checkPermission($name)
284 $r = $this->checkCreatePermissionEntity();
286 elseif ($name ==
'update')
290 elseif ($name ==
'list')
294 elseif ($name ==
'getfields'){}
295 elseif ($name ==
'get')
299 elseif ($name ==
'delete')
303 elseif ($name ==
'modify')
307 elseif ($name ==
'tryadd')
311 elseif ($name ==
'tryupdate')
315 elseif ($name ==
'trymodify')
331 $saleModulePermissions = self::getApplication()->GetGroupRight(
"sale");
332 if ($saleModulePermissions ==
"D")
334 $r->addError(
new Error(
'Access Denied', 200040300010));
343 $saleModulePermissions = self::getApplication()->GetGroupRight(
"sale");
344 if ($saleModulePermissions <
"W")
346 $r->addError(
new Error(
'Access Denied', 200040300020));