- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/delivery/externallocationmap.php
- Класс: BitrixSaleDeliveryfor
- Вызов: for::setExternalLocation2
static function setExternalLocation2($srvId, $locationId, $xmlId, $updateExist = false)
{
if($xmlId == '')
throw new ArgumentNullException('code');
if($srvId == '')
throw new ArgumentNullException('srvId');
if(intval($locationId) <= 0)
throw new ArgumentNullException('locationId');
static $locCache = array();
if(!isset($locCache[$srvId]))
{
$locCache[$srvId] = array();
$eRes = ExternalTable::getList(array(
'filter' => array(
'=SERVICE_ID' => $srvId,
),
'select' => array('ID', 'SERVICE_ID', 'LOCATION_ID', 'XML_ID')
));
while($loc = $eRes->fetch())
$locCache[$srvId][$loc['LOCATION_ID'].'##'.$loc['XML_ID']] = $loc['ID'];
}
if(!empty($locCache[$srvId][$locationId.'##'.$xmlId]))
{
if($updateExist)
{
$res = ExternalTable::update(
$locCache[$srvId][$locationId.'##'.$xmlId],
array(
'SERVICE_ID' => $srvId,
'XML_ID' => $xmlId,
'LOCATION_ID' => $locationId
));
return $res;
}
else
{
$result = new BitrixMainEntityUpdateResult();
$result->addError(new Error('External location already exists', 'EXTERNAL_LOCATION_EXISTS'));
return $result;
}
}
else
{
$res = ExternalTable::add(array(
'SERVICE_ID' => $srvId,
'XML_ID' => $xmlId,
'LOCATION_ID' => $locationId
));
$locCache[$srvId][$locationId.'##'.$xmlId] = $res->getId();
return $res;
}
}