/** * Adds a new location * * @param mixed[] $data to be added. Additional data keys could be passed: * * <ul> * <li> * NAME string[] : add name string to a newly created location * </li> * <li> * EXTERNAL string[] : add external data records to a newly created location * </li> * </ul> * * @param mixed[] $behaviour an additional behaviour flags: * * <ul> * <li> * REBALANCE boolean (default: true) : do rebalancing after add * </li> * </ul> * * @return Bitrix\Main\Entity\AddResult the result of add operation */ public static function add($data = array(), $behaviour = array('REBALANCE' => true, 'RESET_LEGACY' => true)) { if (!is_array($behaviour)) { $behaviour = array(); } if (!isset($behaviour['REBALANCE'])) { $behaviour['REBALANCE'] = true; } if (!isset($behaviour['RESET_LEGACY'])) { $behaviour['RESET_LEGACY'] = true; } if (isset($data['EXTERNAL'])) { $external = $data['EXTERNAL']; unset($data['EXTERNAL']); } if (isset($data['NAME'])) { $name = $data['NAME']; unset($data['NAME']); } // force code to lowercase if (isset($data['CODE'])) { $data['CODE'] = ToLower($data['CODE']); } // you are not allowed to modify tree data over LocationTable::add() self::applyRestrictions($data); // store tree data and basic $addResult = parent::add($data, $behaviour); // add connected data if ($addResult->isSuccess()) { $primary = $addResult->getId(); // external if (isset($external)) { ExternalTable::addMultipleForOwner($primary, $external); } // names if (isset($name)) { Name\LocationTable::addMultipleForOwner($primary, $name); } if ($behaviour['RESET_LEGACY'] && intval($data['TYPE_ID'])) { $type = TypeTable::getList(array('filter' => array('=ID' => $data['TYPE_ID']), 'select' => array('CODE')))->fetch(); if (strlen($type['CODE']) && in_array($type['CODE'], array('COUNTRY', 'REGION', 'CITY'))) { static::resetLegacyPath(); } } $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data'); } $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data'); return $addResult; }
/** * Adds a new location * * @param mixed[] $data to be added. Additional data keys could be passed: * * <ul> * <li> * NAME string[] : add name string to a newly created location * </li> * <li> * EXTERNAL string[] : add external data records to a newly created location * </li> * </ul> * * @param mixed[] $behaviour an additional behaviour flags: * * <ul> * <li> * REBALANCE boolean (default: true) : do rebalancing after add * </li> * </ul> * * @return Bitrix\Main\Entity\AddResult the result of add operation */ public static function add($data = array(), $behaviour = array('REBALANCE' => true)) { if (isset($data['EXTERNAL'])) { $external = $data['EXTERNAL']; unset($data['EXTERNAL']); } if (isset($data['NAME'])) { $name = $data['NAME']; unset($data['NAME']); } // force code to lowercase if (isset($data['CODE'])) { $data['CODE'] = ToLower($data['CODE']); } // you are not allowed to modify tree data over LocationTable::add() self::applyRestrictions($data); // store tree data and basic $addResult = parent::add($data, $behaviour); // add connected data if ($addResult->isSuccess()) { $primary = $addResult->getId(); // external if (isset($external)) { ExternalTable::addMultipleForOwner($primary, $external); } // names if (isset($name)) { Name\LocationTable::addMultipleForOwner($primary, $name); } } $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data'); return $addResult; }