Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
importonecbase.php
1
<?php
2
3
namespace
Bitrix\Sale\Exchange
;
4
5
6
use
Bitrix\Main\ArgumentException
;
7
use
Bitrix\Main\Error
;
8
use
Bitrix\Main\Event
;
9
use
Bitrix\Main\Localization\Loc
;
10
use
Bitrix\Sale\Exchange\Entity\EntityImport
;
11
use
Bitrix\Sale\Exchange\Entity\ShipmentImport
;
12
use
Bitrix\Sale\Exchange\Entity\UserProfileImport
;
13
use
Bitrix\Sale\Exchange\OneC\ConverterFactory
;
14
use
Bitrix\Sale\Exchange\OneC\DocumentBase
;
15
use
Bitrix\Sale\Exchange\OneC\DocumentType
;
16
use
Bitrix\Sale\Internals\Fields
;
17
use
Bitrix\Sale\Result
;
18
19
abstract
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
());
185
$settings =
ManagerImport::getSettingsByType
($entityTypeId);
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
221
protected
function
resolveDocumentTypeId
(array
$fields
)
222
{
223
return
OneC\DocumentBase::resolveRawDocumentTypeId(
$fields
);
224
}
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
{
239
return
ManagerImport::getDirectionType
();
240
}
241
246
protected
function
logger
(array $items)
247
{
248
return
$this->
loggerEntities
($items);
249
}
250
}
Bitrix\Catalog\Model\Event
Definition
event.php:11
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadLanguageFile
static loadLanguageFile($file, $language=null, $normalize=true)
Definition
loc.php:224
Bitrix\Sale\Exchange\Entity\EntityImport
Definition
entityimport.php:17
Bitrix\Sale\Exchange\Entity\ShipmentImport
Definition
shipmentimport.php:23
Bitrix\Sale\Exchange\Entity\UserProfileImport
Definition
userprofileimport.php:11
Bitrix\Sale\Exchange\EntityType\getDescription
static getDescription($typeID)
Definition
entitytype.php:209
Bitrix\Sale\Exchange\ImportOneCBase
Definition
importonecbase.php:20
Bitrix\Sale\Exchange\ImportOneCBase\resolveDocumentTypeId
resolveDocumentTypeId(array $fields)
Definition
importonecbase.php:221
Bitrix\Sale\Exchange\ImportOneCBase\setFields
setFields(array $values)
Definition
importonecbase.php:35
Bitrix\Sale\Exchange\ImportOneCBase\modifyEntity
modifyEntity($item)
Definition
importonecbase.php:113
Bitrix\Sale\Exchange\ImportOneCBase\setConfig
static setConfig($option='', $value=true)
Definition
importonecbase.php:95
Bitrix\Sale\Exchange\ImportOneCBase\getDirectionType
getDirectionType()
Definition
importonecbase.php:237
Bitrix\Sale\Exchange\ImportOneCBase\convertDocument
convertDocument(DocumentBase $document)
Definition
importonecbase.php:182
Bitrix\Sale\Exchange\ImportOneCBase\checkSettings
static checkSettings()
Definition
importonecbase.php:84
Bitrix\Sale\Exchange\ImportOneCBase\checkFields
checkFields(array $items)
Definition
importonecbase.php:65
Bitrix\Sale\Exchange\ImportOneCBase\getMessage
static getMessage()
Definition
importonecbase.php:229
Bitrix\Sale\Exchange\ImportOneCBase\$config
static $config
Definition
importonecbase.php:29
Bitrix\Sale\Exchange\ImportOneCBase\configuration
static configuration()
Definition
importonecbase.php:89
Bitrix\Sale\Exchange\ImportOneCBase\EVENT_ON_EXCHANGE_CONFIGURE_IMPORTER
const EVENT_ON_EXCHANGE_CONFIGURE_IMPORTER
Definition
importonecbase.php:24
Bitrix\Sale\Exchange\ImportOneCBase\DELIVERY_SERVICE_XMLID
const DELIVERY_SERVICE_XMLID
Definition
importonecbase.php:25
Bitrix\Sale\Exchange\ImportOneCBase\$fields
$fields
Definition
importonecbase.php:28
Bitrix\Sale\Exchange\ImportOneCBase\logger
logger(array $items)
Definition
importonecbase.php:246
Bitrix\Sale\Exchange\ImportOneCBase\resolveOwnerEntityTypeId
resolveOwnerEntityTypeId($typeId)
Bitrix\Sale\Exchange\ImportOneCBase\setField
setField($name, $value)
Definition
importonecbase.php:47
Bitrix\Sale\Exchange\ImportOneCBase\getField
getField($name)
Definition
importonecbase.php:56
Bitrix\Sale\Exchange\ImportOneCBase\parse
parse(array $rawFields)
Definition
importonecbase.php:155
Bitrix\Sale\Exchange\ImportPattern
Definition
importpattern.php:7
Bitrix\Sale\Exchange\ManagerImport\configure
static configure(ImportBase $entity)
Definition
managerimport.php:29
Bitrix\Sale\Exchange\ManagerImport\getSettingsByType
static getSettingsByType($typeId)
Definition
managerimport.php:71
Bitrix\Sale\Exchange\ManagerImport\getDirectionType
static getDirectionType()
Definition
managerimport.php:21
Bitrix\Sale\Exchange\OneC\ConverterFactory
Definition
converterfactory.php:11
Bitrix\Sale\Exchange\OneC\DocumentBase
Definition
documentbase.php:16
Bitrix\Sale\Exchange\OneC\DocumentBase\getId
getId()
Definition
documentbase.php:95
Bitrix\Sale\Exchange\OneC\DocumentBase\getExternalId
getExternalId()
Definition
documentbase.php:108
Bitrix\Sale\Exchange\OneC\DocumentBase\getTypeId
getTypeId()
Definition
documentbase.php:49
Bitrix\Sale\Exchange\OneC\DocumentType
Definition
documenttype.php:10
Bitrix\Sale\Internals\Fields
Definition
fields.php:6
Bitrix\Sale\Exchange
Definition
basetrait.php:2
Bitrix\Sale\Exchange\loggerEntities
loggerEntities(array $items)
Definition
loggertrait.php:41
Bitrix\Sale\Exchange\LoggerTrait
trait LoggerTrait
Definition
loggertrait.php:12
modules
sale
lib
exchange
importonecbase.php
Создано системой
1.10.0