Вы здесь

CDEK API

Интеграция со СДЭК.

Модуль CDEK API интегрирует Друпал с API службы доставки СДЭК. Модуль предназначен для разработчиков.

Возможности

  • Получение списка стран, регионов, городов и пунктов получения заказов СДЭК
  • Полученные данные кешируются для улучшения быстродействия
  • Расчёт стоимости доставки рассчитывается на основе указанных параметров
  • Элемент формы для выбора точки получения заказа

Настройка

Параметры модуля можно найти на странице /admin/config/services/cdek-api

Кодирование

API methods

$cdek = \Drupal::service('cdek_api');

// Get a list of order pickup points.
$result = $cdek->getOrderPickupPoints();

// Get a list of order pickup points that
// match the specified parameters.
$result = $cdek->getOrderPickupPoints([
  'countryid' => 1,
  'cityid' => 44,
  'type' => 'PVZ',
  'allowedcod' => TRUE,
  'weightmax' => 100,
]);

// Get a list of countries.
$result = $cdek->getCountries();

// Get a list of regions for all countries.
$result = $cdek->getRegions();

// Get a list of regions for specified country.
$result = $cdek->getRegions(['countryid' => 1]);

// Get a list of cities for all countries and regions.
$result = $cdek->getCities();

// Get a list of cities for specified country.
$result = $cdek->getCities(['countryid' => 1]);

// Get a list of cities for specified region.
$result = $cdek->getCities(['regionid' => 7]);

// Calculate delivery rate without authorization.
$result = $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.
$result = $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.
$result = $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().
  ],
];

Группа проекта: