Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
importbase.php
1<?php
3
7
8abstract class ImportBase
9{
10 const ITEM_ITEM = 'ITEM';
11 const ITEM_SERVICE = 'SERVICE';
12
13 protected $collisionErrors = false;
14 protected $collisionWarnings = false;
15 protected $logging = false;
16
18 protected $fields;
20 protected $settings = null;
21
23 protected $loadCriterion = null;
25 protected $loadLogger = null;
27 protected $loadCollision = null;
28
30 protected $logger = array();
31
35 static public function getFieldExternalId()
36 {
37 throw new Main\NotImplementedException('The method is not implemented.');
38 }
39
43 abstract public function getEntity();
44
48 abstract public function getOwnerTypeId();
49
55 abstract public function add(array $params);
56
62 abstract public function update(array $params);
63
69 abstract public function delete(array $params = null);
70
75 abstract protected function checkFields(array $fields);
76
81 abstract public function load(array $fields);
82
87 public function import(array $params)
88 {
89 $result = new Sale\Result();
90 if($this->getId()>0)
91 {
92 $result = $this->update($params);
93 }
94 elseif($this->isImportable())
95 {
96 $result = $this->add($params);
97 }
98
99 $this->initLogger();
100
101 return $result;
102 }
103
107 abstract public function getId();
108
112 public function getExternalId()
113 {
114 $entity = $this->getEntity();
115 if(!empty($entity))
116 {
117 return $entity->getField(static::getFieldExternalId());
118 }
119
120 return null;
121 }
122
126 abstract public function isImportable();
127
132 public function setFields(array $values)
133 {
134 foreach ($values as $key=>$value)
135 {
136 $this->setField($key, $value);
137 }
138 }
139
144 public function setField($name, $value)
145 {
146 $this->fields->set($name, $value);
147 }
148
153 public function getField($name)
154 {
155 return $this->fields->get($name);
156 }
157
161 public function getFieldValues()
162 {
163 return $this->fields->getValues();
164 }
165
169 abstract public function refreshData(array $fields);
170
174 protected function getFieldsTraits()
175 {
176 $entity = $this->getEntity();
177 return $entity->getFieldValues();
178 }
179
180 abstract public function initFields();
181
186 {
187 $this->setFields($fields);
188 }
189
194 {
195 $this->settings = $settings;
196 }
197
201 public function loadCriterion(ICriterion $criterion)
202 {
203 $this->loadCriterion = $criterion;
204 }
205
212 public function getLoadedCriterion()
213 {
215 }
216
221 public function getCurrentCriterion($entity)
222 {
224 $criterions = $this->getLoadedCriterion();
225 return $criterions::getCurrent($this->getOwnerTypeId(), $entity);
226 }
227
231 public function loadCollision(ICollision $collision)
232 {
233 $this->loadCollision = $collision;
234 }
235
241 public function getLoadedCollision()
242 {
244 }
245
249 public function getSettings()
250 {
251 return $this->settings;
252 }
253
258 public function getCurrentCollision($typeId)
259 {
261 $collision = $this->getLoadedCollision();
262 return $collision::getCurrent($typeId);
263 }
264
265 public function loadLogger(Exchange\Internals\Logger $logger)
266 {
267 $this->loadLogger = $logger;
268 }
269
270 public function getLoadedLogger()
271 {
272 return $this->loadLogger;
273 }
274
275 public function getCurrentLogger()
276 {
277 $logger = $this->getLoadedLogger();
278 return $logger::getCurrent();
279 }
280
281 public function initLogger()
282 {
283 $this->logging = true;
284
285 $logger = $this->getCurrentLogger();
286 $this->logger = $logger;
287 }
288
292 public function getLogger()
293 {
294 return $this->logger;
295 }
296
300 public function hasCollisionErrors()
301 {
303 }
304
308 public function hasCollisionWarnings()
309 {
311 }
312
313 public function hasLogging()
314 {
315 return $this->logging;
316 }
317
322 static private function getSaleExport()
323 {
324 static $exportProfiles = null;
325
326 if($exportProfiles === null)
327 {
328 $exportProfiles = \CSaleExport::getSaleExport();
329 }
330 return $exportProfiles;
331
332 }
333
339 static public function getBusinessValue(\Bitrix\Sale\IBusinessValueProvider $entity)
340 {
341 $order = static::getBusinessValueOrderProvider($entity);
342
343 $orderFields = $order->getFieldValues();
344 $paymentList = array();
345 $shipmentList = array();
346
347 if($paymentCollection = $order->getPaymentCollection())
348 {
350 foreach ($paymentCollection as $payment)
351 {
352 $paymentList[$payment->getId()] = $payment->getPaymentSystemName();
353 }
354 }
355 if($shipmentCollection = $order->getShipmentCollection())
356 {
358 foreach ($shipmentCollection as $shipment)
359 {
360 $shipmentList[$shipment->getId()] = $shipment->getDeliveryName();
361 }
362 }
363
364 $arProp = \CSaleExport::prepareSaleProperty(
365 $orderFields,
366 false,
367 false,
368 $paymentList,
369 $shipmentList,
370 $locationStreetPropertyValue,
371 $order
372 );
373
374 $exportProfiles = static::getSaleExport();
375 $exportProfile = (array_key_exists($order->getPersonTypeId(), $exportProfiles) ? $exportProfiles[$order->getPersonTypeId()]: array());
376
377 $properties = \CSaleExport::prepareSalePropertyRekv(
378 $entity,
379 $exportProfile,
380 $arProp,
381 $locationStreetPropertyValue
382 );
383 $properties['REKV'] = static::modifyRekv($properties['REKV'], $exportProfile);
384
385 return $properties;
386 }
387
393 static private function modifyRekv($rekv, array $exportProfile)
394 {
395 $result = array();
396 foreach ($rekv as $k=>$v)
397 {
398 if(isset($exportProfile[$k]) && $exportProfile[$k]['NAME'] <> '' && $v <> '')
399 {
400 $result[$exportProfile[$k]['NAME']] = $v;
401 }
402 }
403 return $result;
404 }
405
411 {
412 throw new Main\NotImplementedException('The method is not implemented.');
413 }
414}
loadLogger(Exchange\Internals\Logger $logger)
static getBusinessValueOrderProvider(\Bitrix\Sale\IBusinessValueProvider $entity)
loadCriterion(ICriterion $criterion)
loadSettings(ISettings $settings)
loadCollision(ICollision $collision)