Пример #1
0
 public static function createService($service)
 {
     $res = Location\ExternalServiceTable::add($service);
     if (!$res->isSuccess()) {
         throw new Main\SystemException('External service creation failed: ' . implode(', ', $res->getErrorMessages()));
     }
     return $res->getId();
 }
Пример #2
0
 public function copyZipCodes()
 {
     global $DB;
     Helper::truncateTable(self::TABLE_LOCATION_EXTERNAL);
     $zipServiceId = false;
     $zip = Location\ExternalServiceTable::getList(array('filter' => array('=CODE' => 'ZIP')))->fetch();
     if (intval($zip['ID'])) {
         $zipServiceId = intval($zip['ID']);
     }
     if ($zipServiceId === false) {
         $res = Location\ExternalServiceTable::add(array('CODE' => 'ZIP'));
         if (!$res->isSuccess()) {
             throw new Main\SystemException('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' => '\\Bitrix\\Sale\\Location\\ExternalTable', 'exactFields' => array('LOCATION_ID', 'XML_ID', 'SERVICE_ID'), 'parameters' => array('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 (strlen($item['LOCATION_ID']) && strlen($item['ZIP'])) {
                 $loc2External->insert(array('LOCATION_ID' => $item['LOCATION_ID'], 'XML_ID' => $item['ZIP'], 'SERVICE_ID' => $zipServiceId));
             }
         }
         $loc2External->flush();
     }
 }