- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/entitymarker.php
- Класс: BitrixSaleEntityMarker
- Вызов: EntityMarker::tryFixErrorsByOrder
static function tryFixErrorsByOrder(Order $order, $markerId = null)
{
$result = new Result();
if ($order->getId() <=0)
{
return $result;
}
$resultList = array(
'LIST' => array(),
'ERRORS' => array(),
);
$filter = array(
'filter' => array(
'=ORDER_ID' => $order->getId(),
'=TYPE' => static::ENTITY_MARKED_TYPE_AUTO,
),
'select' => array('ID', 'ENTITY_TYPE', 'ENTITY_ID', 'CODE', 'SUCCESS'),
'order' => array('ID' => 'DESC')
);
if (intval($markerId) > 0)
{
$filter['filter']['=ID'] = intval($markerId);
}
else
{
$filter['filter']['!=SUCCESS'] = static::ENTITY_SUCCESS_CODE_DONE;
}
$res = static::getList($filter);
while($markerData = $res->fetch())
{
if ($markerData['SUCCESS'] == static::ENTITY_SUCCESS_CODE_DONE)
{
$resultList['LIST'][$markerData['ID']] = static::ENTITY_SUCCESS_CODE_DONE;
}
else
{
if (!$entity = static::getEntity($order, $markerData['ENTITY_TYPE'], $markerData['ENTITY_ID']))
{
$result->addError(new ResultError(MainLocalizationLoc::getMessage('SALE_ENTITY_MARKER_ENTITY_NOT_FOUND'), 'SALE_ENTITY_MARKER_ENTITY_NOT_FOUND'));
return $result;
}
if (!($entity instanceof IEntityMarker))
{
return $result;
}
$r = $entity->tryFixError($markerData['CODE']);
if ($r->isSuccess() && !$r->hasWarnings())
{
$markerData['SUCCESS'] = static::ENTITY_SUCCESS_CODE_DONE;
}
else
{
$markerData['SUCCESS'] = static::ENTITY_SUCCESS_CODE_FAIL;
if (!isset($resultList['ERRORS'][$markerData['ID']]))
{
$resultList['ERRORS'][$markerData['ID']] = array();
}
$resultList['ERRORS'][$markerData['ID']] = array_merge($resultList['ERRORS'][$markerData['ID']], $r->getWarningMessages());
if (!$r->isSuccess())
{
$result->addErrors($r->getErrors());
}
}
static::updateMarker($markerData['ID'], $markerData, $order, $entity);
$resultList['LIST'][$markerData['ID']] = ($markerData['SUCCESS'] == static::ENTITY_SUCCESS_CODE_DONE);
}
}
if (!empty($resultList) && is_array($resultList))
{
$result->setData($resultList);
}
return $result;
}