- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/location/migration/migrate.php
- Класс: BitrixSaleLocationMigrationCUpdaterLocationPro
- Вызов: CUpdaterLocationPro::copyZipCodes
public function copyZipCodes()
{
global $DB;
Helper::truncateTable(self::TABLE_LOCATION_EXTERNAL);
$zipServiceId = false;
$zip = LocationExternalServiceTable::getList(array('filter' => array('=CODE' => 'ZIP')))->fetch();
if(intval($zip['ID']))
$zipServiceId = intval($zip['ID']);
if($zipServiceId === false)
{
$res = LocationExternalServiceTable::add(array('CODE' => 'ZIP'));
if(!$res->isSuccess())
throw new MainSystemException('Cannot add external system: '.implode(', ', $res->getErrors()), 0, __FILE__, __LINE__);
$zipServiceId = $res->getId();
}
if($this->TableExists(self::TABLE_LOCATION_ZIP))
{
$loc2External = new BlockInserter(array(
'entityName' => 'BitrixSaleLocationExternalTable',
'exactFields' => array('LOCATION_ID', 'XML_ID', 'SERVICE_ID'),
'parameters' => array(
//'autoIncrementFld' => 'ID',
'mtu' => 9999
)
));
$res = $DB->query('select * from '.self::TABLE_LOCATION_ZIP);
while($item = $res->fetch())
{
$item['LOCATION_ID'] = trim($item['LOCATION_ID']);
$item['ZIP'] = trim($item['ZIP']);
if(mb_strlen($item['LOCATION_ID']) && mb_strlen($item['ZIP']))
{
$loc2External->insert(array(
'LOCATION_ID' => $item['LOCATION_ID'],
'XML_ID' => $item['ZIP'],
'SERVICE_ID' => $zipServiceId
));
}
}
$loc2External->flush();
}
}