Developer notes
Data model (InnoDB)
Section titled “Data model (InnoDB)”| Table | Purpose |
|---|---|
?:kv_ppk_sessions |
One row per pack attempt: order_id, company_id (the order’s company), user_id (packer), state (O open, D done, C cancelled), lock_key, times, status_from / status_to / status_changed, counters scans, errors, overrides, end_note (left, takeover:<user id>). |
?:kv_ppk_lines |
Lines of a session: item_id of the order line, product, product code, codes (JSON list of barcodes), location, required, packed, override + reason, serial_mode (N, O optional, R required), serials (JSON). |
?:kv_ppk_log |
Pack log events: order_id, session_id, user_id, event, item_id, code, qty, note, created_at. |
Uninstalling drops the three tables. Deleting an order (delete_order hook) deletes its rows.
Locking and idempotency
Section titled “Locking and idempotency”- One open session per order.
lock_keyisUNIQUEand holds the order id while the session is open (NULL otherwise). Opening inserts withINSERT IGNORE; a second packer gets no row and sees the holder. A takeover closes the old session withUPDATE … WHERE session_id = ? AND state = 'O'before inserting. - Quantities never exceed the order. A scan is
UPDATE lines SET packed = packed + n WHERE … AND packed + n <= required; no row changed means “too many”. - Serialised actions. Every scan, undo, override and completion of a session runs under the MySQL named lock
GET_LOCK('<db hash>:kv_ppk_s<session>'), and completion also underkv_ppk_o<order>. - Status changes once. Completion links serial numbers first (an error leaves the session open), then claims the session with
UPDATE sessions SET state = 'D', lock_key = NULL WHERE session_id = ? AND state = 'O'. Only the request that changed the row callsfn_change_order_status(); every other request answers “already completed”. The order status is re-read before the claim: an order that left the waiting statuses (except into the target status) is not completed. - Lock nesting. Completion takes the session lock and then the order lock. On MySQL older than 5.7.5 a second
GET_LOCKreleases the first one; the guarantee still holds there, because only the conditional claim (WHERE state = 'O') changes the status. - Order edited during packing. When the packer resumes, lines are re-synchronised with the order: removed lines are dropped, lowered quantities cap
packed, new lines are added; scanned units of unchanged lines are kept.
Code matching
Section titled “Code matching”Codes::normalize() strips control characters (scanner prefixes and suffixes, GS1 group separators), trims and upper-cases. Codes::key() compares GTIN-8, UPC-A (12), EAN-13 and GTIN-14 as 14-digit GTINs (so UPC-A = EAN-13 with a leading zero, while a short numeric SKU never collides) and other codes without spaces. Each line’s codes are: the product code stored on the order line, the product’s current code, and the values of the barcode feature (split by commas, semicolons or new lines; spaces inside one code are ignored). 5*CODE is a quantity prefix (only *, so codes such as 5XL-RED are never misread). Order numbers accept 1234, #1234, Order 1234 and the core Barcode add-on value (its prefix + order id).
Status change
Section titled “Status change”fn_change_order_status($order_id, $target, '', $force) with $force = ['C' => false] when “Notify the customer” is off and [] otherwise: keys that are not set (customer when on, administrator A and vendor V always) follow the order status settings. fn_get_notification_rules() is not used, because it tests !empty() and would read 'N' as “send”. Core rules apply (stock, payments, other add-ons’ hooks). The packing slip is the core orders.print_packing_slip.
Options
Section titled “Options”CS-Cart 4.17+ keeps product codes per product (option inventory codes are gone; variations are separate products). When a scanned key matches several open lines whose labels differ (same product, different options), scan answers choose with choices (item ids) and the code; the station highlights those lines and the packer’s tap posts kv_pick_pack.pick (item_id, code), which re-checks that the code belongs to the line and counts it atomically (scan_choice event).
Hooks and integration points
Section titled “Hooks and integration points”| Where | What |
|---|---|
PHP hook delete_order |
Removes sessions, lines and log of the order. |
controllers/backend/orders.post.php (details) |
Adds the Pick & Pack tab (navigation.tabs.kv_ppk). |
Template hook orders:tabs_extra (post) |
The pack log tab content. |
Template hooks index:styles / index:scripts (admin, post) |
Admin CSS and the station script. |
schemas/menu/menu.post.php, menu_vendor.post.php |
Orders → Pick & Pack. |
schemas/permissions/admin.post.php |
view_orders for the queue and pick lists, change_order_status for the station. |
schemas/permissions/vendor_multivendor.post.php |
Vendor access per mode (only while the vendor setting is on). |
Serial Numbers & Warranty Tracker is used only through its public classes and only when it is active (SerialBridge): Products::tracked(), Products::componentsOf(), Products::owner(), Serials::find(), Orders::serialsByItem() and Orders::setLine(). There is no dependency in addon.xml.
Multi-Vendor and Ultimate
Section titled “Multi-Vendor and Ultimate”Every query adds the context: is_parent_order != 'Y' on Multi-Vendor, and company_id = runtime.company_id when a vendor (or an Ultimate storefront) is selected. Each station action loads the order through Orders::row() and refuses orders of another company; a session can only be driven by the user who opened it. On Ultimate, settings are read for the order’s storefront.
Full page cache (4.21)
Section titled “Full page cache (4.21)”The add-on renders nothing on the storefront, so no page of the full page cache can contain its output.
Station protocol
Section titled “Station protocol”The station posts kv_pick_pack.scan|pick|undo|override|complete|ping with session_id (and code, item_id, reason) as AJAX requests and receives kv_ppk: result (ok, serial, over, wrong, duplicate, serial_taken, choose, ignored, error), message, item_id, lines (the stored state of every line), progress, and for completion already, status_changed, status_to, slip_url. Scans are queued in the browser and sent one after another; the server state is always what the screen shows.
File map
Section titled “File map”app/addons/kv_pick_pack/ addon.xml init.php func.php controllers/backend/kv_pick_pack.php queue, station actions, pick lists controllers/backend/orders.post.php pack log tab schemas/menu/ schemas/permissions/ schemas/settings/variants.functions.post.php Tygh/Addons/KvPickPack/ Config Codes Orders Station PickList History SerialBridge Barcode License/ Upgrade/design/backend/templates/addons/kv_pick_pack/ views/kv_pick_pack/{manage,pack,picklist}.tpl hooks/orders/tabs_extra.post.tpl hooks/index/{styles,scripts}.post.tpl license/design/backend/css/addons/kv_pick_pack/{styles,license}.lessjs/addons/kv_pick_pack/func.jsvar/langs/en/addons/kv_pick_pack.po