本文整理汇总了PHP中Bitrix\Sale\Location\LocationTable::add方法的典型用法代码示例。如果您正苦于以下问题:PHP LocationTable::add方法的具体用法?PHP LocationTable::add怎么用?PHP LocationTable::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitrix\Sale\Location\LocationTable
的用法示例。
在下文中一共展示了LocationTable::add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
// ok, so country were created, now create demo-city
$data = array(
'CODE' => 'demo_city_'.WIZARD_SITE_ID,
'TYPE_ID' => $types['CITY'],
'NAME' => array(),
'PARENT_ID' => $countryId
);
foreach($arLanguages as $langID)
{
$data["NAME"][$langID] = array(
'NAME' => $shopLocation
);
}
$res = \Bitrix\Sale\Location\LocationTable::add($data);
if($res->isSuccess())
$location = 'demo_city_'.WIZARD_SITE_ID;
}
}
}
}
}
else
{
$location = 0;
$dbLocation = CSaleLocation::GetList(Array("ID" => "ASC"), Array("LID" => $lang, "CITY_NAME" => $shopLocation));
if($arLocation = $dbLocation->Fetch())//if there are no data in module
{
$location = $arLocation["ID"];
示例2: AddLocationUnattached
protected static function AddLocationUnattached($typeCode, $names = array())
{
static $types;
if ($types == null) {
$types = self::getTypes();
}
if (!intval($types[$typeCode])) {
return false;
}
foreach (GetModuleEvents('sale', 'OnBefore' . ucfirst(ToLower($typeCode)) . 'Add', true) as $arEvent) {
if (ExecuteModuleEventEx($arEvent, array($names)) === false) {
return false;
}
}
if (!is_array($names)) {
$names = array();
}
$name = $names['NAME'];
$shortName = $names['SHORT_NAME'];
unset($names['NAME']);
unset($names['SHORT_NAME']);
$fields = array();
foreach ($names as $lang => $n) {
$fields['NAME'][$n['LID']] = array('NAME' => $n['NAME'], 'SHORT_NAME' => $n['SHORT_NAME']);
}
if (!isset($fields['NAME']['en'])) {
$fields['NAME']['en'] = array('NAME' => $name, 'SHORT_NAME' => $shortName);
}
$fields['CODE'] = 'randstr' . rand(999, 99999) . rand(999, 99999) . rand(999, 99999);
$fields['TYPE_ID'] = $types[$typeCode];
$fields['PARENT_ID'] = 0;
$id = false;
$res = \Bitrix\Sale\Location\LocationTable::add($fields);
if ($res->isSuccess()) {
$id = $res->getId();
$uRes = \Bitrix\Sale\Location\LocationTable::update($id, array('CODE' => $id));
foreach (GetModuleEvents('sale', 'On' . ucfirst(ToLower($typeCode)) . 'Add', true) as $arEvent) {
ExecuteModuleEventEx($arEvent, array($id, $names));
}
}
return $id;
}
示例3: importFile
public static function importFile(&$descriptior)
{
$timeLimit = ini_get('max_execution_time');
if ($timeLimit < $descriptior['TIME_LIMIT']) {
set_time_limit($descriptior['TIME_LIMIT'] + 5);
}
$endTime = time() + $descriptior['TIME_LIMIT'];
if ($descriptior['STEP'] == 'rebalance') {
Location\LocationTable::resort();
Location\LocationTable::resetLegacyPath();
$descriptior['STEP'] = 'done';
}
if ($descriptior['STEP'] == 'import') {
if (!isset($descriptior['DO_SYNC'])) {
$res = \Bitrix\Sale\Location\LocationTable::getList(array('select' => array('CNT')))->fetch();
$descriptior['DO_SYNC'] = intval($res['CNT'] > 0);
}
if (!isset($descriptior['TYPES'])) {
$descriptior['TYPE_MAP'] = static::getTypeMap($descriptior['TYPE_FILE']);
$descriptior['TYPES'] = static::createTypes($descriptior['TYPE_MAP']);
$descriptior['SERVICE_MAP'] = static::getServiceMap($descriptior['SERVICE_FILE']);
$descriptior['SERVICES'] = static::getExistedServices();
}
$csvReader = new CSVReader();
$csvReader->LoadFile($descriptior['FILE']);
while (time() < $endTime) {
$block = $csvReader->ReadBlockLowLevel($descriptior['POS'], 100);
if (!count($block)) {
break;
}
foreach ($block as $item) {
if ($descriptior['DO_SYNC']) {
$id = static::checkLocationCodeExists($item['CODE']);
if ($id) {
$descriptior['CODES'][$item['CODE']] = $id;
continue;
}
}
// type
$item['TYPE_ID'] = $descriptior['TYPES'][$item['TYPE_CODE']];
unset($item['TYPE_CODE']);
// parent id
if (strlen($item['PARENT_CODE'])) {
if (!isset($descriptior['CODES'][$item['PARENT_CODE']])) {
$descriptior['CODES'][$item['PARENT_CODE']] = static::checkLocationCodeExists($item['PARENT_CODE']);
}
$item['PARENT_ID'] = $descriptior['CODES'][$item['PARENT_CODE']];
}
unset($item['PARENT_CODE']);
// ext
if (is_array($item['EXT'])) {
foreach ($item['EXT'] as $code => $values) {
if (is_array($values) && !empty($values)) {
if (!isset($descriptior['SERVICES'][$code])) {
$descriptior['SERVICES'][$code] = static::createService(array('CODE' => $code));
}
foreach ($values as $value) {
if (!strlen($value)) {
continue;
}
$item['EXTERNAL'][] = array('SERVICE_ID' => $descriptior['SERVICES'][$code], 'XML_ID' => $value);
}
}
}
}
unset($item['EXT']);
$res = Location\LocationTable::add($item, array('REBALANCE' => false, 'RESET_LEGACY' => false));
if (!$res->isSuccess()) {
throw new Main\SystemException('Cannot create location');
}
$descriptior['CODES'][$item['CODE']] = $res->getId();
}
}
if (!count($block)) {
unset($descriptior['CODES']);
$descriptior['STEP'] = 'rebalance';
}
}
return $descriptior['STEP'] == 'done';
}
示例4: AddLocationPart
private static function AddLocationPart($creat, $type, $parent, $sort)
{
$langs = self::getLanguages();
$types = self::getTypes();
$creatFlds = array();
if(is_numeric($creat))
{
// check whether location exists...
$res = Location\LocationTable::getList(array('filter' => array('='.$type.'_ID' => $creat, 'TYPE_ID' => $types[$type]), 'select' => array('ID'), 'limit' => 1))->fetch();
if($res['ID'])
{
$parent = intval($res['ID']);
}
else
{
if($type == 'COUNTRY')
$res = self::GetCountryByID($creat); //!!!
elseif($type == 'REGION')
$res = self::GetRegionByID($creat); //!!!
elseif($type == 'CITY')
$res = self::GetCityByID($creat); //!!!
if(!$res) // no such type exists, smth strange
throw new Exception('No such '.$type);
// create location using type found
$creatFlds[$type.'_ID'] = $res['ID'];
$creatFlds['NAME'] = array();
foreach($langs as $lid)
{
if($type == 'COUNTRY')
$name = self::GetCountryLangByID($res['ID'], $lid); //!!!
elseif($type == 'REGION')
$name = self::GetRegionLangByID($res['ID'], $lid); //!!!
elseif($type == 'CITY')
$name = self::GetCityLangByID($res['ID'], $lid); //!!!
$creatFlds['NAME'][$lid] = array(
'NAME' => $name['NAME'],
'SHORT_NAME' => $name['SHORT_NAME']
);
}
}
}
elseif(is_array($creat)) // should create type
{
$creatFlds[$type.'_ID'] = self::getFreeId($type);
$creatFlds['NAME'] = array();
foreach($creat as $lid => $name)
{
$creatFlds['NAME'][$lid] = array(
'NAME' => $name['NAME'],
'SHORT_NAME' => $name['SHORT_NAME']
);
}
}
if(!empty($creatFlds))
{
$creatFlds['PARENT_ID'] = $parent;
$creatFlds['TYPE_ID'] = $types[$type];
$creatFlds['CODE'] = rand(999,99999999);
if($sort !== false)
$creatFlds['SORT'] = $sort;
$res = Location\LocationTable::add($creatFlds);
if(!$res->isSuccess())
throw new Exception('Cannot add location');
$parent = $res->getId();
Location\LocationTable::update($parent, array('CODE' => $parent));
}
return $parent;
}