Skip to content

Developer notes

Part of B2B Sales Rep Portal.

Tables (InnoDB, prefix kv_srep_): reps, assignments (customer, scope, rep, allow_shop, consent), sessions (token hash, expiry, status, end reason), log, orders (attribution: rep, via S = shop session / A = assigned, list and charged totals, overrides), rules (commission and maximum discount per rep and category), commissions (ledger: type C commission or A adjustment, status P/E/V/D). Scope = company id of the rep: 0 for the store or marketplace, a vendor id for a vendor rep, the storefront id on Ultimate.

before_dispatch (session guard), dispatch_before_display (banner data, signed-in visitors only), user_logout_after, update_user_pre (keeps e-mail and password of the customer), update_user_profile_post (territory assignment), calculate_cart_items (line discounts), pre_add_to_cart (vendor scope), pre_place_order, place_order, change_order_status, get_order_info, delete_order, delete_user, delete_company. Template hooks: index:footer (banner), checkout:product_info (discount field), orders:info, profiles:account_update, profiles:my_account_menu, admin orders:staff_only_note.

index.php?dispatch=kv_srep.state answers {"on": true|false} (add-on enabled and licensed) for the licence test harness. It returns no other data.

Entities (administrator API key; privileges view_kv_srep / manage_kv_srep; a vendor administrator only with vendor reps on and only the own scope):

Entity Calls
/api/kv_srep_reps GET list / one, POST {"email": "...", "max_discount": 8, "commission_rate": 3, "territories": "US, DE"}, PUT, DELETE
/api/kv_srep_assignments GET (q, rep_id, unassigned=Y), PUT /:user_id {"rep_id": 5} or {"allow_shop": "N"}, DELETE /:user_id
/api/kv_srep_commissions GET (rep_id, status, type, order_id, time_from, time_to) with totals, PUT /:id {"status": "D", "payout_ref": "..."}
/api/kv_srep_sessions GET live sessions, DELETE /:id revokes

Start and stop are POST with a per-session token (kv_srep_token) and an Origin / Referer check; the core security hash is not used because it is switched off when the 4.21 full page cache is on. The session is a database row; the PHP session only points to it and every request re-validates row, rep, assignment and consent. Details in the class comment of Tygh\Addons\KvSalesRepPortal\Impersonation.

Order management edits: when an administrator edits an order placed with rep discounts in order management, CS-Cart recalculates the line prices from the catalog; the order record keeps the list and charged totals for reference. Login add-ons that hook fn_login_user (two-factor, passkeys) see the two logins of a session start and stop.