Bitrix Site Manager

CSaleLocation::Add

int
CSaleLocation::Add(
  array arFields
);

The method Add adds a new location, optionally including the country and the city.

Parameters

ParameterDescription
arFields Associated array of the location parameters. The following keys are possible:
  • SORT - sort weight;
  • COUNTRY_ID - the ID of the country currently existing in the system. If the country has not been previously created, the COUNTRY key must be specified;
  • COUNTRY - array of the country parameters; if the country has been previously created and COUNTRY_ID contains a valid ID, this array is not used;
  • WITHOUT_CITY - flag (Y/N) specifying the location without a city (country only). If "N", the CITY key must be specified;
  • CITY - array containing the city parameters. Not used if WITHOUT_CITY is "Y".
The COUNTRY array must have the following keys specified:
  • NAME - the country name (language-independent);
  • SHORT_NAME - country name abbreviation (language-independent);
  • <language ID> - the key is the language name. The value is an associated array in the format:
    array("LID" => "language ID",
          "NAME" => "country name in this language",
          "SHORT_NAME" => "country name abbreviation 
                           in this language").
    Such pair must be specified for every language in the system.
The CITY array must have the following keys specified:
  • NAME - the city name (language-independent);
  • SHORT_NAME - city name abbreviation (language-independent);
  • <language ID> - the key is the language name. The value is an associated array in the format:
    array("LID" => "language ID",
          "NAME" => "country name in this language",
          "SHORT_NAME" => "country name abbreviation 
                           in this language").
    Such pair must be specified for every language in the system.

Return Values

Returns the new location ID on success, or false otherwise.

Example



<?
$arFields = array(
   "SORT" => 100,
   "COUNTRY_ID" => 0,
   "WITHOUT_CITY" => "N"
);

$arCountry = array(
   "NAME" => "France",
   "SHORT_NAME" => "FR",
   "fr" => array(
      "LID" => "fr",
      "NAME" => "France",
      "SHORT_NAME" => "FR"
      )
   "en" => array(
      "LID" => "en",
      "NAME" => "France",
      "SHORT_NAME" => "FR"
      ),
);

$arFields["COUNTRY"] = $arCountry;

$arCity = array(
   "NAME" => "Paris",
   "SHORT_NAME" => "Paris",
   "fr" => array(
      "LID" => "fr",
      "NAME" => "Paris",
      "SHORT_NAME" => "Paris"
      ),
   "en" => array(
      "LID" => "en",
      "NAME" => "Paris",
      "SHORT_NAME" => "Paris"
      )
);

$arFields["CITY"] = $arCity;

$ID = CSaleLocation::Add($arFields);
if (IntVal($ID)<=0)
   echo "Error adding location";
?>