Advertising sustains the DA. Ads are hidden for members. Join today

On this page

Code examples

Last updated on
31 January 2019

API methods

Get a list of order pickup points.

$cdek = \Drupal::service('cdek_api');
$points = $cdek->getOrderPickupPoints();

Get a list of order pickup points that match the specified parameters.

$cdek = \Drupal::service('cdek_api');
$points = $cdek->getOrderPickupPoints([
 'countryid' => 1,
 'cityid' => 44,
 'type' => 'PVZ',
 'allowedcod' => TRUE,
 'weightmax' => 100,
]);

Get a list of countries.

$cdek = \Drupal::service('cdek_api');
$countries = $cdek->getCountries();

Get a list of regions for all countries.

$cdek = \Drupal::service('cdek_api');
$regions = $cdek->getRegions();

Get a list of regions for specified country.

$cdek = \Drupal::service('cdek_api');
$regions = $cdek->getRegions(['countryid' => 1]);

Get a list of cities for all countries and regions.

$cdek = \Drupal::service('cdek_api');
$cities = $cdek->getCities();

Get a list of cities for specified country.

$cdek = \Drupal::service('cdek_api');
$cities = $cdek->getCities(['countryid' => 1]);

Get a list of cities for specified region.

$cdek = \Drupal::service('cdek_api');
$cities = $cdek->getCities(['regionid' => 7]);

Calculate delivery rate without authorization.

$cdek = \Drupal::service('cdek_api');
$rate = $cdek->calculateDeliveryRate([
 'senderCityId' => 44,
 'receiverCityId' => 419,
 'dateExecute' => '2018-07-19',
 'tariffId' => 1,
 'goods' => [
 ['weight' => 5, 'length' => 10, 'width' => 10, 'height' => 10],
 ['weight' => 3, 'volume' => 0.1],
 ],
]);

Calculate delivery rate with authorization.

$cdek = \Drupal::service('cdek_api');
$rate = $cdek->calculateDeliveryRate([
 'authLogin' => 'YOUR_CDEK_LOGIN',
 'secure' => 'YOUR_CDEK_PASSWORD',
 'senderCityId' => 44,
 'receiverCityId' => 419,
 'dateExecute' => '2018-07-19',
 'tariffId' => 1,
 'goods' => [
 ['weight' => 5, 'length' => 10, 'width' => 10, 'height' => 10],
 ['weight' => 3, 'volume' => 0.1],
 ],
]);

Calculate delivery rate by taking the authorization and other possible parameters from the settings.

$cdek = \Drupal::service('cdek_api');
$rate = $cdek->calculateDeliveryRate([
 'authLogin' => TRUE,
 'receiverCityId' => 419,
 'goods' => [
 ['weight' => 5, 'length' => 10, 'width' => 10, 'height' => 10],
 ['weight' => 3, 'volume' => 0.1],
 ],
]);

Form element

Basic usage.

$form['point'] = [
 '#type' => 'cdek_api_select',
 '#title' => 'Order pickup point',
];

Advanced usage.

$form['point'] = [
 '#type' => 'cdek_api_select',
 '#title' => 'Order pickup point',
 '#default_value' => 'KSD30',
 '#required' => TRUE,
 '#cdek_api_options' => [
 // Sub-elements can be hidden.
 'hide_country' => TRUE,
 'hide_region' => TRUE,
 'hide_city' => TRUE,
 ],
 '#cdek_api_params' => [
 // Params for \Drupal\cdek_api\Cdek::getOrderPickupPoints().
 ],
];

Help improve this page

Page status: No known problems

You can: