Developer notes
How the exemption works
Section titled “How the exemption works”The core removes tax when fn_get_customer_tax_exempt_status($cart, $auth) is true (the customer’s tax_exempt flag). The add-on handles the core hook calculate_cart_items (before shipping and taxes are calculated):
- Storefront: it sets
$auth['tax_exempt'] = 'Y'on the copy of the auth data that the calculation uses. The session auth and the customer profile are not touched. - Admin order management: it sets
$cart['user_data']['tax_exempt']for the calculation and restores the original value at the start of the next calculation ($cart['kv_txc_orig']). - The destination is
fn_get_customer_location($auth, $cart)(shipping address). The certificate must be approved, started (valid_from), not expired (expires_at), belong to the customer, match the storefront (Ultimate) and cover the destination. - A customer who is already exempt through the core flag is left alone.
- The applied certificate is available as
$cart['kv_txc'](certificate_id,cert_type,certificate_number,scope,expires_at,country,state).
The hook place_order_post writes ?:kv_txc_orders (and marks ?:orders.tax_exempt = 'Y') for the order and for the vendor child orders of a Multi-Vendor order. get_order_info adds $order_info.kv_txc.
Extension hook
Section titled “Extension hook”fn_set_hook('kv_tax_exempt_certificates_apply', $cert, $cart, $auth, $user_id, $country, $state): change the certificate or empty $cert to veto the exemption for a cart.
Tables
Section titled “Tables”| Table | Content |
|---|---|
?:kv_txc_certificates |
One row per certificate: user, storefront (company_id, Ultimate), status P pending, A approved, R rejected, V revoked; type, number, holder, scope (approved), customer scope (requested), valid_from, expires_at (0 = none), reason, timestamps. “Expired” and “not yet valid” are computed, never stored. |
?:kv_txc_documents |
File name, storage path (custom_files/kv_tax_exempt_certificates/<id>/<random>.<ext>), size. |
?:kv_txc_log |
Audit log: action, actor (admin, customer, system), message. |
?:kv_txc_orders |
Order reference: certificate id, number, type, scope, destination country and state. |
REST API
Section titled “REST API”/api/kv_tax_exempt_certificates (administrator authentication, privileges view_kv_tax_exempt_certificates / manage_kv_tax_exempt_certificates). Customers and vendors have no access.
GET /api/kv_tax_exempt_certificates?status=P|A|R|V|X|E&user_id=&q=&page=&items_per_page=GET /api/kv_tax_exempt_certificates/<id>PUT /api/kv_tax_exempt_certificates/<id> {"action":"approve","scope":"US:CA,US:NY","expires_at":"2027-12-31","valid_from":"2026-12-01"}PUT /api/kv_tax_exempt_certificates/<id> {"action":"reject","reason":"Certificate is not signed"}PUT /api/kv_tax_exempt_certificates/<id> {"action":"revoke","reason":"Business closed"}approve without expires_at keeps the expiry date the customer gave (none = no expiry); dates must be YYYY-MM-DD; an unparsable date, an expiry in the past and valid_from after expires_at answer 400. Status filters: X = approved but expired, E = approved and expiring inside the reminder window. Documents are never part of the API. Send Content-Type: application/json.
The customer’s certificates, documents and history are deleted in the core hook post_delete_user. With the core GDPR add-on active, schemas/gdpr/user_data.post.php exposes the certificate number and holder name to the export and anonymisation tools.
Storage and security
Section titled “Storage and security”- Files go to the
custom_filesstorage under random names with a neutral.binextension (the corevar/.htaccessallows some extensions to be served directly), and the add-on writes a deny-all.htaccessand anindex.phpinto its folder; on servers without.htaccesssupport blockvar/in the server configuration. Downloads are checked per request (owner or administrator with the view privilege), sent as attachments withX-Content-Type-Options: nosniffandContent-Security-Policy: sandbox. - Uploads are limited by extension, size, number and content: the first bytes must match the extension (PDF header, real image of the right type), and files that contain script or HTML markers are refused. Nothing is executed or converted.
- Antivirus: the add-on does not scan files. If your host provides a scanner, hook it with your own add-on on
kv_tax_exempt_certificatesuploads (for example in a pre controller) or scanvar/custom_filesregularly.
Compatibility notes
Section titled “Compatibility notes”- Hooks used:
calculate_cart_items,place_order_post,get_order_info,post_delete_user,before_dispatch(all documented and present in 4.17.2 to 4.21.2). - No Smarty plugin directories, no
{php}; templates work on Smarty 4 and 5. E-mail templates use plain Twig 2 / 3 syntax. - Pages of the add-on are account, checkout and admin pages; they are not part of the full page cache. The storefront flags are the same for every visitor.