Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
importoneccontragentbase.php
1<?php
2
3
5
10
11IncludeModuleLangFile($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/sale/lib/exchange/importonecpackage.php');
12
14{
15 protected function resolveDocumentTypeId(array $fields)
16 {
17 return OneC\DocumentType::USER_PROFILE;
18 }
19
24 protected function convert(array $documents)
25 {
26 $result = new Result();
27 $list = array();
28
29 foreach($documents as $document)
30 {
31 $list[] = $this->convertDocument($document);
32 }
33
34 if($result->isSuccess())
35 {
36 $result = $this->checkFields($list);
37 if($result->isSuccess())
38 {
39 $result->setData($list);
40 }
41 }
42
43 return $result;
44 }
45
50 protected function import(array $items)
51 {
52 $result = new Result();
53
54 foreach($items as $item)
55 {
56 if($item->getOwnerTypeId() == static::getUserProfileEntityTypeId())
57 {
58 $params = $item->getFieldValues();
59 $fields = $params['TRAITS'];
60
61 $personalTypeId = $params['TRAITS']['PERSON_TYPE_ID'] = $item->resolvePersonTypeId($fields);
62
63 $property = $params['ORDER_PROPS'];
64 if(!empty($property))
65 {
66 $params['ORDER_PROP'] = $item->getPropertyOrdersByConfig($personalTypeId, array(), $property);
67 }
68
69 unset($params['ORDER_PROPS']);
70 $item->setFields($params);
71
72 $r = $item->load($fields);
73
74 if(intval($personalTypeId)<=0)
75 $r->addError(new Error(GetMessage("SALE_EXCHANGE_PACKAGE_ERROR_PERSONAL_TYPE_IS_EMPTY", array("#DOCUMENT_ID#"=>$fields['XML_ID'])), "PACKAGE_ERROR_PERSONAL_TYPE_IS_EPMTY"));
76
77 if($r->isSuccess())
78 {
79 $r = $this->modifyEntity($item);
80
81 if(intval($item->getId())<=0)
82 $r->addError(new Error(GetMessage("SALE_EXCHANGE_PACKAGE_ERROR_USER_IS_EMPTY", array("#DOCUMENT_ID#"=>$fields['XML_ID'])), "PACKAGE_ERROR_USER_IS_EPMTY"));
83 }
84
85 if(!$r->isSuccess())
86 {
87 $result->addErrors($r->getErrors());
88 break;
89 }
90 }
91 }
92
93 return $result;
94 }
95
96 public static function configuration()
97 {
98 parent::configuration();
99
100 ManagerImport::registerInstance(static::getUserProfileEntityTypeId(), OneC\ImportSettings::getCurrent());
101 }
102
107 protected function logger(array $items)
108 {
109 $xmlStreem = $this->getRawData();
110 foreach ($items as $item)
111 {
112 if($item->hasLogging())
113 {
114 $item->getLogger()
115 ->setField('MESSAGE', $xmlStreem);
116 }
117 }
118 return parent::logger($items);
119 }
120
121 protected function resolveOwnerEntityTypeId($typeId)
122 {
123 $entityTypeId = EntityType::UNDEFINED;
124
125 switch ($typeId)
126 {
127 case OneC\DocumentType::USER_PROFILE:
128 $entityTypeId = static::getUserProfileEntityTypeId();
129 break;
130 }
131 return $entityTypeId;
132 }
133
135 {
137 }
138}
convertDocument(DocumentBase $document)
static registerInstance($typeId, ISettingsImport $settings, ICollision $collision=null, ICriterion $criterion=null)