Developer notes
Technical reference for developers who customize Sendcloud Shipping.
Add-on identity
Section titled “Add-on identity”| Item | Value |
|---|---|
| Add-on id | kv_sendcloud |
| Function prefix | fn_kv_sendcloud_ |
| Language variables | kv_sendcloud.* |
| CSS scope | .kv-sendcloud |
| PHP namespace | Tygh\Addons\KvSendcloud |
| Preset | shipping (generated by kv new --kind integration) |
Structure
Section titled “Structure”| Class | Role |
|---|---|
Client\BaseClient |
HTTP (cURL, TLS verification, timeouts), JSON, error mapping, masked logging |
Client\Api |
The Sendcloud v3 calls: shippingOptions, servicePoints, announce, cancel, shipment, tracking, returnPortalUrl, document, documents (merged); HTTP Basic authentication |
Options |
Request body of /shipping-options and the choice of one option (carrier list, exact code, cheapest / fastest, home vs. service point) |
RateCalculator |
Checkout rate: one Sendcloud call per route and weight (memory and 5 minute session cache), currency conversion, markup / free threshold / fallback |
Points |
Service point search and mapping, selection in the cart, the point stored with the order (kv_sendcloud_points) |
Shipments |
Announce (create + label, 1 to 15 parcels), multicollo rows, merged labels, cancel, tracking, webhook status, core shipment, payload mapping |
Contracts |
Contract mode per vendor (marketplace / own / disabled): default, allowed modes, vendor choice, administrator lock, account resolution, 1.0 migration plan |
Client |
Client per company (api(): the account of the vendor’s mode now) or per account (account(): the account a label was bought with), the connection test |
Accounts, Secret |
Credentials (test and live) sealed with AES-256-GCM; one account for the store / marketplace and one per vendor with an own account |
Config, Access |
Settings, who may see and manage what |
Installer |
Shipping services; migrate() = idempotent 1.0 -> 1.1 step run by Upgrade\Synchronizer |
Queue, Jobs, JobException |
Job queue: back-off 5 min / 15 min / 1 h / 3 h / 12 h, per-job isolation, overlap lock; handlers in Jobs::handle(), recurring work in Jobs::schedule() |
Log |
Event log with masking, filters, CSV, retention |
Webhook |
Signature check and event ids; the controller kv_sendcloud.webhook?c=<account> stores the event as a job |
Database tables
Section titled “Database tables”| Table | Purpose |
|---|---|
?:kv_sendcloud_accounts |
Credentials per company (secrets sealed), last connection check, token cache |
?:kv_sendcloud_log |
Log |
?:kv_sendcloud_jobs |
Queue |
?:kv_sendcloud_shipments |
One row per parcel: Sendcloud shipment id (provider_ref, shared by the parcels of a multicollo shipment), parcel id, parcel_no / parcel_count, account_id (account the label was bought with; -1 only before the 1.1 migration), core_shipment_id, option code, tracking, label file |
?:kv_sendcloud_vendors |
Contract mode per vendor: contract M (marketplace) / O (own) / D (disabled), locked Y = fixed by the administrator; no row = the default |
?:kv_sendcloud_points |
The service point chosen at checkout, per order |
Hooks used
Section titled “Hooks used”PHP hooks: change_order_status_post (automatic labels), get_order_info (attach the point and kv_sc_parcels, the parcels with their tracking links), place_order, place_suborders (Multi-Vendor sub-orders), delete_order, template_document_order_context_init (point on invoices and e-mails). Template hooks: checkout:shipping_method (picker card), orders:totals_shipping and orders:shipment_info (storefront order: point, parcels and tracking links), orders:tabs_extra, orders:customer_shot_info, orders:list_extra_links (admin order). The bulk action is a context menu item (schemas/context_menu/orders.post.php).
Account rule for custom code: new work for a company goes through Client::api($company_id) (returns null when the vendor’s mode is disabled or the account is not connected); work on an existing label uses Client::account(Shipments::accountOf($row)).
Sendcloud endpoints used
Section titled “Sendcloud endpoints used”POST /shipping-options (with functionalities.multicollo for several parcels), GET /service-points, POST /shipments/announce (1 to 15 parcels; label_file only for one parcel), POST /shipments/{id}/cancel (all parcels), GET /shipments/{id}, GET /parcels/tracking/{tracking_number}, GET /parcels/{id}/documents/label, GET /parcel-documents/label?parcels=.. (merged labels, up to 20 parcels), GET /shipments/{id}/return-portal-url, all below https://panel.sendcloud.sc/api/v3. Webhook: parcel_status_changed, header Sendcloud-Signature (hex HMAC-SHA256 of the raw body).
Test the HTTP layer without the provider
Section titled “Test the HTTP layer without the provider”The base URL can be overridden for tests in config.local.php (development only):
$config['kv_sendcloud_base_url'] = 'http://127.0.0.1:11830';node tests/mock-server/server.js 11830 starts a local stand-in of the provider API (two accounts, multicollo); node tests/e2e/e2e.mjs runs the HTTP end-to-end test against it; php tests/unit.php runs the unit tests; tests/php/store_test.php and tests/php/upgrade_test.php run inside a dev store (contract modes, multicollo, the 1.0 -> 1.1 upgrade).
Template overrides
Section titled “Template overrides”Admin templates live in design/backend/templates/addons/kv_sendcloud/. Do not edit them in a store; they are replaced on update.