LocationEntity: CDEK cities and postal codes in Joomla
LocationEntity in WT CDEK for Joomla covers cities, regions, postal codes and coordinates. This reference explains its purpose, parameters and PHP examples for Joomla extensions.
LocationEntity provides CDEK geography: regions, cities, postal codes, coordinates and city suggestions.
Access the entity through the Cdek facade:
$location = $cdek->location();
getRegions()
Signature
public function getRegions(array $request_options = []): array
REST API
GET /v2/location/regions
Purpose
Lists regions. Defaults: size=1000, page=0, lang=rus. An array of country codes is joined with commas.
Parameters
country_codes: array or comma-separated string; optional size, page, lang.
Returns
Region records.
Example
<?php
declare(strict_types=1);
use Webtolk\Cdekapi\Cdek;
defined('_JEXEC') or die;
$cdek = new Cdek();
$regions = $cdek->location()->getRegions([
'country_codes' => ['RU'],
]);
getCities()
Signature
public function getCities(array $request_options = []): array
REST API
GET /v2/location/cities
Purpose
Lists cities. Defaults: size=500, page=0, lang=rus.
Parameters
Filters include country_codes, postal_code, region_code, city, fias_guid, size, page, lang.
Returns
City records with CDEK codes and reference information.
Example
<?php
declare(strict_types=1);
use Webtolk\Cdekapi\Cdek;
defined('_JEXEC') or die;
$cdek = new Cdek();
$cities = $cdek->location()->getCities([
'postal_code' => '630099',
'city' => 'Новосибирск',
'size' => 1,
]);
getPostalCodes()
Signature
public function getPostalCodes(int $city_code): array
REST API
GET /v2/location/postalcodes
Purpose
Lists postal codes for a CDEK city code.
Parameters
$city_code: CDEK city code.
Returns
Postal codes, or an error if the code is not supplied.
Example
<?php
declare(strict_types=1);
use Webtolk\Cdekapi\Cdek;
defined('_JEXEC') or die;
$cdek = new Cdek();
$indexes = $cdek->location()->getPostalCodes(270);
getCityByCoordinates()
Signature
public function getCityByCoordinates(array $request_options = []): array
REST API
GET /v2/location/coordinates
Purpose
Resolves a location using coordinates and normalizes short key names.
Parameters
Use latitude/longitude, or lat/lng, or lat/lon.
Returns
Resolved location data.
Example
<?php
declare(strict_types=1);
use Webtolk\Cdekapi\Cdek;
defined('_JEXEC') or die;
$cdek = new Cdek();
$result = $cdek->location()->getCityByCoordinates([
'lat' => 55.030199,
'lng' => 82.920430,
]);
suggestCities()
Signature
public function suggestCities(string $city_name, string $country_code = ''): array
REST API
GET /v2/location/suggest/cities
Purpose
Returns city name suggestions for autocomplete.
Parameters
Required $city_name; optional ISO $country_code.
Returns
Suggestions, typically including city_uuid, code, full_name and country_code.
Example
<?php
declare(strict_types=1);
use Webtolk\Cdekapi\Cdek;
defined('_JEXEC') or die;
$cdek = new Cdek();
$result = $cdek->location()->suggestCities('Саратов', 'RU');