Developer notes
What the add-on touches
Section titled “What the add-on touches”- Shipments are created with core
fn_update_shipment()and removed with corefn_delete_shipments(); order statuses are changed withfn_change_order_status(). Core hooks (create_shipment,create_shipment_post,update_shipment_before_send_notification,delete_shipmentsand others) fire as for a shipment created by hand. Core tables are not altered. - Customer e-mails are the core event
order.shipment_updatedwith the settings of CS-Cart; “no e-mail” passes the notification rulesC,AandVas false. - The add-on registers
get_shipments_info_postandupdate_shipment_before_send_notificationto name custom carriers and fill their tracking link (carrier_info), anddelete_companyto remove a company’s carriers, presets and import log. - A custom carrier is stored in
shipments.carrieraskvbti_<carrier_id>. - Core adds one “shipment created” notice per shipment; during an import these are dropped from the session so a large import does not flood the page.
Tables
Section titled “Tables”All ?:kv_bti_*, InnoDB: carriers, presets, imports (one record per upload or API call: status draft, preview, running, done, undone), rows (one per shipment job: state ready, working, done, error, skipped, failed, undone; the shipment ids, the previous and new order status). They are dropped on uninstall.
Run safety
Section titled “Run safety”- A row is claimed with
UPDATE ... WHERE state = 'ready'and processed only whenROW_COUNT() = 1; a MySQL lock per import and per order keeps a double click or a second request from creating a shipment twice. - Every row is validated again against the live order right before the shipment is created.
- A row left in
workingby a request that died is adopted when a shipment with the same tracking number was created after the import started, otherwise it is marked failed and never retried automatically.
REST API
Section titled “REST API”Endpoint /api/kv_tracking_imports, administrator or vendor API key, Content-Type: application/json on requests with a body (send DELETE without a body and without that header: CS-Cart answers an empty JSON body with 400). Needs the privileges View orders (GET) and Edit order details (POST, DELETE), plus Change order status for order_status. A vendor reaches only its own orders and imports. Multi-Vendor: CS-Cart lets vendor API keys use the REST API only while the core Vendor privileges add-on is active (otherwise every vendor call answers 403); administrator keys always work.
| Method | Path | Body / result |
|---|---|---|
| GET | /api/kv_tracking_imports |
list of imports (page, items_per_page) |
| GET | /api/kv_tracking_imports/:id |
one import with its rows |
| POST | /api/kv_tracking_imports |
create (see below) |
| DELETE | /api/kv_tracking_imports/:id |
undo the latest import that created shipments; 409 when it cannot be undone |
POST body:
{ "rows": [ {"order_id": 1001, "carrier": "DHL", "tracking_number": "JD014600006281230704"}, {"order_id": 1002, "carrier": "UPS", "tracking_number": "1Z999AA10123456784", "items": [{"sku": "TSHIRT-RED", "qty": 2}], "comment": "Parcel 1 of 2"} ], "order_status": "C", "notify": "core", "default_carrier": "dhl", "dry_run": false}rows: at most 500 per request (and the “Maximum rows per import” setting). Rows of one order, carrier and tracking number that list items are merged into one shipment.order_status(optional): an order status code such asC.notify:core(default) follows the shipment notification settings of CS-Cart,nonesends no e-mail.default_carrier(optional): carrier name or code for rows without one.dry_run: trueanswers with the check of every row and stores nothing:{"dry_run": true, "rows_ready": 1, "rows": [{"line": 1, "order_id": 1001, "state": "ready", "message": "", "shipment_ids": []}]}.- A real import answers 201 with
import_id,status, the counters,can_undoand the rows withshipment_ids. Imports through the API appear in the import log with the source “REST API”. - A real import runs in one request. If the call times out (a proxy cuts it), post the same rows again: rows whose tracking number is already on a shipment of the order are skipped, so nothing is created twice.
- Privileges: a real import needs Edit order details (the privilege of the core shipment pages) and, with
order_status, Change order status; otherwise it answers 403. Undo needs the same; without Change order status it deletes the shipments and leaves the order statuses as they are. - Without a valid license a real import answers 403; GET and
dry_runkeep working. With the endpoint switched off in the settings every call answers 403.
Row states: ready (dry run), done, skipped (nothing to do: already shipped, tracking number already there, duplicate row), error (the message says why), failed (CS-Cart refused the shipment), undone.