
ms_CDEK2
Внимание
This documentation is for component version 2.4.1 and above.
Внимание
The msDeliveryProps component is no longer required.
Requirements
- MODX 2.8.x
- PHP >=7.4
- MySQL 5.7
Features
- Delivery cost calculation according to configured tariffs.
- Pickup point selection from list or map (requires Yandex JavaScript API and HTTP Geocoder token).
- Address suggestions from DaData.
How it works
The component needs a postal code in field [name="index"] to calculate delivery. The user can type it or you can enable address suggestions so the code is filled when a suggestion is chosen.
After the code is received, standard miniShop2 logic runs and delivery cost is calculated. On Order.getcost.response.success, if pickup delivery is selected, the pickup list is loaded; in any case delivery status (all data from CDEK API) is loaded to show the user if the page has the right block.
If the pickup list was loaded and the page has a map block, the map is drawn. Selecting a pickup in the list moves the map to its coordinates and highlights the marker. Selecting on the map updates the list.
Информация
The component can use country: add field [name="country"]. Country is used for suggestions, pickup list, and cost calculation.
Quick start
Внимание
With SendIt 2.4.0+, the checkout page must have at least one html element with attribute data-si-form
Информация
None of the html blocks below are required for delivery cost calculation except the postal code field.
After installing, complete the first 6 steps:
- Go to system settings and select namespace ms_cdek2;
- Set ms_cdek2_login and ms_cdek2_password;
- Set sender postal code in ms_cdek2_sender_index;
- Set delivery method IDs in ms_cdek2_deliveries (door — door delivery, pvz — pickup);
Подробнее
E.g. door ID 9, pickup 10:
{"door":"9","pvz":"10"}. - Set delivery IDs and CDEK tariff IDs in ms_cdek2_tariffs (door tariff 137, pickup 136);
Подробнее
E.g. door ID 9, pickup 10:
{"9":"137","10":"136"}. - Set checkout form template ID in ms_cdek2_template (so frontend scripts load only on that template);
- If using pickup delivery, add to the checkout form chunk:
<div data-mscdek-list></div>Информация
If shipping is not from Russia, set sender country in ms_cdek2_sender_country.
Внимание
The pickup list must be in a select as in chunk mscdekListWrap, or not shown at all.
Информация
If you do not show the pickup list, use a hidden field instead of the list block:
<div class="hide" data-mscdek-list></div>Hidden field
<input type="hidden" name="point">Map with pickup list
- Get a key for JavaScript API and HTTP Geocoder;
- Set it in ms_cdek2_yandex_api_key;
- Add to the checkout template:
<div class="hide" data-mscdek-map></div>Address suggestions
- Get a token from DaData;
- Set it in ms_cdek2_dadata_token;
- Add attribute
data-mscdek-suggest-fieldto the address input; - Add to the checkout template:
<ul class="hide" data-mscdek-suggest-list></ul>Delivery timeframe
- Add to the checkout template:
<div class="hide" data-mscdek-status></div>Package count calculation
From 2.6.0 the component can calculate package count in several ways. Method is set in ms_cdek2_packages_calc_type. Possible values:
0— one package (default);1— one package per unique product in cart;2— one package per product in cart;3— from volume of one package (volume from ms_cdek2_default_size). E.g. product 20×30×10 cm, 1 kg, qty 3; ms_cdek2_default_size 20×30×20 → two packages:
$packages = [
[
'weight' => 2,
'length' => 20,
'width' => 30,
'height' => 20
],
[
'weight' => 1,
'length' => 20,
'width' => 30,
'height' => 10
],
];4— one package, size and weight from system settings.5— one package, size from settings, weight = sum of cart product weights.
Settings ms_cdek2_use_product_count, ms_cdek2_use_individual_sizes, ms_cdek2_use_individual_weight control whether real quantity, product dimensions, and product weight are used. Default is false (use default size/weight and count = 1).
Внимание
For methods 0,1,2,3 use ms_cdek2_default_size for single product package size; for 4,5 use full package size. Same for ms_cdek2_package_default_weight.
Информация
For 0,1,3: package weight = sum of (product weight × qty); length/width = max of products; height = sum of heights (stacked). For 2: package = product. For 4,5: from settings.
International delivery
CDEK supports Kazakhstan and Belarus. Pass recipient country in order field country.
Внимание
miniShop2 does not handle select fields; for a country select you need JS:
const countryField = document.querySelector('select[name="country"]');
countryField && countryField.addEventListener('change', () => {
miniShop2.Order.add('country', countryField.value);
});If DaData token is not set, use country code ISO 3166-1 alpha 2. Otherwise use country name in Russian.