Skip to content

Developer notes

Technical reference for developers who customize Lot & Batch Traceability + Recall Notices.

Item Value
Add-on id kv_lot_batch_traceability
Function prefix fn_kv_lot_batch_traceability_
Language variables kv_lot_batch_traceability.*
CSS scope .kv-lbt, .kv-lbt-*
PHP namespace Tygh\Addons\KvLotBatchTraceability
Dispatch kv_lbt.* (admin, vendor and storefront)
Database tables ?:kv_lbt_*
Table Contents
kv_lbt_lots One row per lot: company, product, lot_number, supplier, reference, certificate, notes, produced_ymd / expiry_ymd (YYYYMMDD integers, no time zone), qty_received, qty_available, status (A active, H hold, R recalled, C closed). Unique per product + lot number.
kv_lbt_products Per-product settings: track, alloc_mode (default, fefo, fifo, manual), min_shelf_days (-1 = store setting).
kv_lbt_alloc Lot allocated to an order line: order, item_id, product, lot, lot number and expiry copied at allocation time, quantity, source (A auto, M manual).
kv_lbt_ship Which lot left in which shipment (order, shipment, item, lot, quantity).
kv_lbt_recalls Recalls: title, reason, instructions, contact, authority reference, status (D draft, A active, C closed), public flag, timestamps.
kv_lbt_recall_lots Lots of a recall with a snapshot of the product name, lot number and expiry.
kv_lbt_targets Affected order lines: order, customer name and e-mail, product, lot, quantity, notice state (N, S, F, X), sent time, private token, read time, outcome.
kv_lbt_log Activity log: event, message, recall, lot, order, user, time.
kv_lbt_attempts Rate limit of the public lot check (hashed IP, time).

company_id is the owner of the product: the vendor on Multi-Vendor, the owning storefront on CS-Cart Ultimate. The eight record tables are kept on uninstall (see Retention below).

place_order, edit_place_order, change_order_status_post, create_shipment_post, delete_shipments, delete_order, get_order_info, update_product_post, clone_product, delete_product_post. All have the same arguments in 4.17.2 and 4.22.x.

get_order_info adds an entry to products[].product_options (option_id = 'kv_lbt', name “Lot”) in the order data built for display. Order editing and re-ordering use extra.product_options, which is not touched.

Allocator::ensure($order_info, $force_auto = false) fills the missing units of every tracked line and trims lines that shrank. It is idempotent, takes a GET_LOCK per order and moves lot stock with UPDATE ... WHERE qty_available >= n, so concurrent requests cannot take the same unit twice. Allocator::candidates($product_id, $mode, $min_shelf_days) returns the lots in allocation order. Parent orders of a split Multi-Vendor cart are skipped.

use Tygh\Addons\KvLotBatchTraceability\Lots;
use Tygh\Addons\KvLotBatchTraceability\Allocator;
use Tygh\Addons\KvLotBatchTraceability\Trace;
use Tygh\Addons\KvLotBatchTraceability\Recalls;
use Tygh\Addons\KvLotBatchTraceability\Notices;
// Receive a lot (returns ['lot_id' => int, 'errors' => []])
Lots::create(['product_id' => 12, 'lot_number' => 'L2611A', 'qty_received' => '120', 'expiry_ymd' => '2027-01-31'], 0);
// Allocate an order now
Allocator::ensure(fn_get_order_info($order_id, false, true, true));
// Who got lot L2611A?
list($rows, $search) = Trace::search(['q' => 'L2611A'], 0);
// Recall
$r = Recalls::create(['title' => '...', 'reason' => '...', 'instructions' => '...'], $lot_ids, 0);
Recalls::activate($r['recall_id']);
Notices::send($r['recall_id']);

Template kv_lot_batch_traceability_recall (area C) in resources/email_templates.xml; valid in Twig 2.14 (CS-Cart 4.17 / 4.18) and 3.11 (4.21). Edit it in Administration → E-mail templates.

Customer data is printed only on orders.details, kv_lbt.notice, kv_lbt.check and kv_lbt.recalls, which the 4.21 full page cache never caches. The account menu link is the same for every signed-in customer. Nothing is printed from index:* or product hooks.

The eight record tables are not dropped on uninstall unless the setting delete_data_on_uninstall is on (Retention class, settings saved in ?:kv_keep and restored on install).

Storefront templates are in var/themes_repository/responsive/templates/addons/kv_lot_batch_traceability/ (copied to every theme on install). Override them in your theme like any add-on template; styles are scoped under .kv-lbt.

app/addons/kv_lot_batch_traceability/
addon.xml, init.php, func.php
resources/email_templates.xml recall notice e-mail
controllers/backend/kv_lbt.php register, lot, trace, recalls, import/export, reports, order actions
controllers/backend/products.post.php product tab data
controllers/backend/orders.post.php order tab data
controllers/frontend/kv_lbt.php public recalls, lot check, private notice + acknowledge
controllers/frontend/orders.post.php recall box on the customer's order page
controllers/frontend/init.post.php account menu flag
schemas/ menu, permissions, settings
Tygh/Addons/KvLotBatchTraceability/
Config, Products, Lots, Allocator, Trace, Recalls, Notices, Lookup, Csv, Report, ClientIp, Retention,
License/*, Upgrade/Synchronizer
design/backend/templates/addons/kv_lot_batch_traceability/ views, components, hooks, license
design/backend/css/addons/kv_lot_batch_traceability/styles.less
js/addons/kv_lot_batch_traceability/backend.js
var/themes_repository/responsive/templates/addons/kv_lot_batch_traceability/ views, components, hooks
var/themes_repository/responsive/css/addons/kv_lot_batch_traceability/styles.less
var/langs/en/addons/kv_lot_batch_traceability.po