1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
importonecbase.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale\Exchange;
4
5
6use Bitrix\Main\ArgumentException;
7use Bitrix\Main\Error;
8use Bitrix\Main\Event;
9use Bitrix\Main\Localization\Loc;
10use Bitrix\Sale\Exchange\Entity\EntityImport;
11use Bitrix\Sale\Exchange\Entity\ShipmentImport;
12use Bitrix\Sale\Exchange\Entity\UserProfileImport;
13use Bitrix\Sale\Exchange\OneC\ConverterFactory;
14use Bitrix\Sale\Exchange\OneC\DocumentBase;
15use Bitrix\Sale\Exchange\OneC\DocumentType;
16use Bitrix\Sale\Internals\Fields;
17use Bitrix\Sale\Result;
18
19abstract class ImportOneCBase extends ImportPattern
20{
21 use LoggerTrait;
22 use BaseTrait;
23
24 const EVENT_ON_EXCHANGE_CONFIGURE_IMPORTER = 'OnExchangeConfigureImporter';
25 const DELIVERY_SERVICE_XMLID = 'ORDER_DELIVERY';
26
28 protected $fields;
29 static protected $config;
30
35 public function setFields(array $values)
36 {
37 foreach ($values as $key=>$value)
38 {
39 $this->setField($key, $value);
40 }
41 }
42
47 public function setField($name, $value)
48 {
49 $this->fields->set($name, $value);
50 }
51
56 public function getField($name)
57 {
58 return $this->fields->get($name);
59 }
60
65 protected function checkFields(array $items)
66 {
67 $result = new Result();
68
69 foreach($items as $item)
70 {
71 $params = $item->getFieldValues();
72 $fields = $params['TRAITS'];
73
74 if($fields[$item::getFieldExternalId()] == '')
75 $result->addErrors(array(new Error(" ".EntityType::getDescription($item->getOwnerTypeId()).": ".GetMessage("SALE_EXCHANGE_EXTERNAL_ID_NOT_FOUND"), 'SALE_EXCHANGE_EXTERNAL_ID_NOT_FOUND')));
76 }
77
78 return $result;
79 }
80
84 static public function checkSettings()
85 {
86 return new Result();
87 }
88
89 static public function configuration()
90 {
91 $event = new Event('sale', static::EVENT_ON_EXCHANGE_CONFIGURE_IMPORTER);
92 $event->send();
93 }
94
95 static protected function setConfig($option='', $value=true)
96 {
97 if($value)
98 {
99 static::$config |= $option;
100 }
101 else
102 {
103 static::$config &= ~$option;
104 }
105 }
106
113 protected function modifyEntity($item)
114 {
115 $result = new Result();
116
117 if(!($item instanceof EntityImport) && !($item instanceof UserProfileImport))
118 throw new ArgumentException("Item must be instanceof EntityImport or UserProfileImport");
119
120 $params = $item->getFieldValues();
121
122 $fieldsCriterion = $fields = &$params['TRAITS'];
123
124 $converter = ConverterFactory::create($item->getOwnerTypeId());
125 $converter::sanitizeFields($item->getEntity(), $fields, $item->getSettings());
126
127 $item->refreshData($fields);
128
129 $criterion = $item->getCurrentCriterion($item->getEntity());
130 $collision = $item->getCurrentCollision($item->getOwnerTypeId());
131
132 if($item instanceof ShipmentImport)
133 $fieldsCriterion['ITEMS'] = $params['ITEMS'];
134
135 if($criterion->equals($fieldsCriterion))
136 {
137 $collision->resolve($item);
138 }
139
140 if(!$criterion->equals($fieldsCriterion) ||
141 ($criterion->equals($fieldsCriterion) && !$item->hasCollisionErrors()))
142 {
143 $result = $item->import($params);
144 }
145
146 return $result;
147 }
148
155 public function parse(array $rawFields)
156 {
157 $result = new Result();
158 $list = array();
159
160 foreach($rawFields as $raw)
161 {
162 $documentTypeId = $this->resolveDocumentTypeId($raw);
163
164 $document = $this->documentFactoryCreate($documentTypeId);
165
166 $fields = $document::prepareFieldsData($raw);
167
168 $document->setFields($fields);
169
170 $list[] = $document;
171 }
172
173 $result->setData($list);
174
175 return $result;
176 }
177
182 protected function convertDocument(DocumentBase $document)
183 {
184 $entityTypeId = $this->resolveOwnerEntityTypeId($document->getTypeId());
186
187 $convertor = $this->converterFactoryCreate($document->getTypeId());
188 $convertor->init(
189 $settings,
190 $entityTypeId,
191 $document->getTypeId()
192 );
193
194 $fields = $convertor->resolveParams($document);
195
196 $loader = Entity\EntityImportLoaderFactory::create($entityTypeId);
197 $loader->loadSettings($settings);
198
199 if($document->getId() <> '')
200 $fieldsEntity = $loader->getByNumber($document->getId());
201 else
202 $fieldsEntity = $loader->getByExternalId($document->getExternalId());
203
204 if(!empty($fieldsEntity['ID']))
205 $fields['TRAITS']['ID'] = $fieldsEntity['ID'];
206
207 $entityImport = $this->entityFactoryCreate($entityTypeId);
208 ManagerImport::configure($entityImport);
209
210 $entityImport->setFields($fields);
211
212 return $entityImport;
213 }
214
215 abstract protected function resolveOwnerEntityTypeId($typeId);
216
225
229 protected static function getMessage()
230 {
231 return Loc::loadLanguageFile($_SERVER["DOCUMENT_ROOT"].'/bitrix/components/bitrix/sale.export.1c/component.php');
232 }
233
237 public function getDirectionType()
238 {
240 }
241
246 protected function logger(array $items)
247 {
248 return $this->loggerEntities($items);
249 }
250}
Определения error.php:15
static getDescription($typeID)
Определения entitytype.php:209
resolveDocumentTypeId(array $fields)
Определения importonecbase.php:221
setFields(array $values)
Определения importonecbase.php:35
static setConfig($option='', $value=true)
Определения importonecbase.php:95
convertDocument(DocumentBase $document)
Определения importonecbase.php:182
checkFields(array $items)
Определения importonecbase.php:65
const EVENT_ON_EXCHANGE_CONFIGURE_IMPORTER
Определения importonecbase.php:24
logger(array $items)
Определения importonecbase.php:246
setField($name, $value)
Определения importonecbase.php:47
parse(array $rawFields)
Определения importonecbase.php:155
static configure(ImportBase $entity)
Определения managerimport.php:29
static getSettingsByType($typeId)
Определения managerimport.php:71
static getDirectionType()
Определения managerimport.php:21
static resolveRawDocumentTypeId(array $document)
Определения documentbase.php:122
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
GetMessage($name, $aReplace=null)
Определения tools.php:3397
$name
Определения menu_edit.php:35
Определения buffer.php:3
loggerEntities(array $items)
Определения loggertrait.php:41
trait LoggerTrait
Определения loggertrait.php:12
$settings
Определения product_settings.php:43
$event
Определения prolog_after.php:141
if(empty($signedUserToken)) $key
Определения quickway.php:257
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$items
Определения template.php:224
$option
Определения options.php:1711