WT CDEK library

WT CDEK library

  • Category: Libraries
  • Version: 1.3.0
  • Date:
Downloads 2923 Hits 4777 CTR 61% Pack Free

A small native PHP Joomla library for working with the CDEK delivery service API v.2. The package consists of a plugin for storing settings, a PHP library and map widgets for selecting order pick-up points. The library is a client for authorization in the CDEK API via OAuth, working with some API methods: obtaining a number of data and calculating the cost of delivery. Joomla 4.2.7 and higher is supported.

WT CDEK library

Description

Attention

This extension is intended for Joomla developers. They can use it as a dependency when developing their extensions for Joomla.

Pull Requests welcome from Joomla developers!

As part of the package

The library is a client for connecting to the CDEK API and several methods for working with it with preliminary verification of the data structure, as well as error handling during the request. To work with the library, you must have the official CDEK API documentation at hand.

https://api-docs.cdek.ru

Connecting the library to your Joomla extension

Install the pkg_lib_wtcdek package as a regular Joomla extension. After installation, enable the System - WT Cdek plugin, fill in client_id and client_secret, and configure scheduler:run through CRON if you use the Joomla Scheduler.

Quick start

<?php

use Webtolk\Cdekapi\Cdek;

\defined('_JEXEC') or die;

$cdek = new Cdek();
// or
$cdek = new Cdek(test_mode: true, client_id: 'your_client_id', client_secret: 'your_client_secret');

Authorization is handled automatically, and the access token is cached through Joomla.

Main changes in 1.3.0

  • the library was moved to an entity-based API with the Cdek facade
  • API logic was split into dedicated entity classes
  • new entities were added: webhooks, prealert, photoDocument, reverse, passport, payment, print, check, intakes, oauth
  • installer script, TarifflistField, TariffinfoField, and updated assets were added
  • location()->suggestCities() now supports the country_code parameter

 

Connecting the CDEK JavaScript widget

The javascript of the widget is designed as a Joomla Web Asset. In our code, we connect it using WebAssetManager as follows:

<?php
use Joomla\CMS\Factory;

defined('_JEXEC') or die('Restricted access');

$doc  = Factory::getApplication()->getDocument();

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $doc->getWebAssetManager();
$wa->useScript('cdek-widget-umd');

Otherwise, when setting up, follow the widget documentation.

Widget Service.php

The widget is a Yandex.map that receives a list of order pick-up points using ajax. To work with this library, when initializing the widget, specify the servicePath parameter - the url for the ajax request. By default, the file is included with the widget service.php, which is the entry point for the ajax request. In this library, the functionality of this file (getting a list of PVZ and calculating tariffs) has been transferred to the Joomla system plugin.

<?php
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Session\Session;

defined('_JEXEC') or die('Restricted access');

$service_url = new Uri(Uri::base());
$service_url->setPath('/index.php');
$service_url->setQuery([
    'option'                => 'com_ajax',
    'plugin'                => 'wtcdek',
    'group'                 => 'system',
    'format'               => 'raw',
    'city_code'          => $city_code, // CDEK area code to get a list of pick-up points only for the selected city
    Session::getFormToken() => 1
]);
// URL string
$service_url->toString();

For javascript, we use either Joomla Script options or php echo, depending on the structure of your extension.

Joomla

Extension type:
Package
Package composition:
Library, Plugin
Joomla version:
4.2.7, 5.2.1, 5.2.2, 6.0.3

What's new

Change

Complete refactoring of the library

The library has been redesigned into an entity-based API with a Cdek facade and a separate query layer. Backward compatibility is not broken, so the library version is 1.3.0.
Addition

Added support for new sections of the SDEC API

Added support for new sections of the SDEC API: webhooks, prealert, printed forms, payment, passport, reverse, intakes and other entities.
Addition

Improved integration with Joomla

Improved integration with Joomla: installer script for layouts, new form fields for tariffs, and updated assets packages.
Addition

Expanded location methods

Expanded location methods, including city hints with the optional country_code parameter.
Addition

New Joomla Form field: Tariffinfo

A new Joomla Form field has been added that displays information about the tariff selected in the Tarifflist type field.
Change

CDEK widget

The official js widget of SDEC has been updated to the latest version.

Related extensions

WebTolk Joomla Extensions

103 Extensions
12 Categories
526 Versions released
672926 Downloads