Developer notes
| Table | Content |
|---|---|
cscart_kv_bca_organizations |
Company accounts (“organizations”: in CS-Cart “company” is the vendor or storefront). company_id = owning storefront on Ultimate (0 = shared). |
cscart_kv_bca_members |
user_id (primary key: one company per customer), organization_id, role (O/A/P/B/V), status (A active, D deactivated, I invited), limits, granted_usergroups, invitation hash + expiry. |
cscart_kv_bca_addresses |
Shared address book. |
cscart_kv_bca_orders |
One row per top order (Multi-Vendor parent order or single order): total, state (N no approval, P pending, A approved, R rejected, C cancelled/withdrawn), reasons, decision data. |
cscart_kv_bca_log |
Activity log per company and order. |
The order status “Awaiting approval” is a normal order status with the status param kv_bca_awaiting = Y (inventory I, payment_received N, calculate_for_payouts N).
How the approval works
Section titled “How the approval works”- Hook
place_order: the core passes the new order status by reference before it callsfn_change_order_status(). When the order needs approval the status is set to Awaiting approval, so the status change from Incomplete takes no stock. On Multi-Vendor the parent order keeps its parent status and each child order (placed withparent_order_id) follows the decision recorded for the parent. - After placement, core
fn_order_placement_routines()empties the cart and opens the thank-you page only for statuses that take stock; any other status counts as a failed order (cart kept, back to checkout). The hooksplacement_routines+get_order_paid_statuses_postlet Awaiting approval count as placed for that one lookup only (order_placement_routinesresets the flag), so reports and payouts never see it as a paid status. - The decision runs under
GET_LOCKper company and the row is inserted inside the lock, so concurrent orders of one company always count each other. - Orders created or edited by staff in the admin panel are not sent for approval; orders created through the REST API are.
allow_place_order_postrefuses viewers, deactivated members, companies on hold, a blocking budget, a payment method outside the company terms and a gateway method when approval is needed.- Approve / reject claim the row with
UPDATE ... WHERE state = 'P'(one decision only) and move each waiting order of the tree throughfn_change_order_status(). change_order_status_postfollows manual status changes and cancellations (budget totals).is_order_allowed_postopens company orders to roles that see all orders (core order page, invoice, Buy again);get_ordersacceptskv_bca_organization_id,kv_bca_user_idandkv_bca_state(it only narrows, never widens a user filter).
PHP hooks of the add-on
Section titled “PHP hooks of the add-on”/** * Before a notification is sent. * @param string $event approval_requested | order_approved | order_rejected | member_invited * @param array $data Event data; $data['to']['customer'] is the recipient */fn_set_hook('kv_b2b_company_accounts_notify_pre', $event, $data);Notification events (Administration > Notifications): kv_b2b_company_accounts.approval_requested, .order_approved, .order_rejected, .member_invited; e-mail templates kv_b2b_company_accounts_*.
Hooks used from other Kavio Labs add-ons
Section titled “Hooks used from other Kavio Labs add-ons”kv_b2b_registration_approved($application_id, $user_id, $assigned)andkv_b2b_registration_declined(...)of B2B Registration & Approval.- Net Terms & Credit Limits: the owner’s credit line is read from
cscart_kv_ntcl_accounts(read only).
Order info
Section titled “Order info”fn_get_order_info() returns $order['kv_bca'] (organization_id, organization_name, state, reasons, user_id) for company orders; templates and other add-ons can use it.
Full page cache (4.21)
Section titled “Full page cache (4.21)”Nothing is printed on cacheable pages. The “My account” menu links live in the session-dependent My account block; everything else is on account pages, checkout and order pages, which are never cached.
Upgrades
Section titled “Upgrades”The add-on ships the Kavio Labs upgrade synchronizer: after files are replaced in place, missing tables, columns, settings and texts are applied on the next admin page view.