Developer notes
Technical reference for developers who customize Buyer Service Fee.
Add-on identity
Section titled “Add-on identity”| Item | Value |
|---|---|
| Add-on id | kv_buyer_service_fee |
| Function prefix | fn_kv_buyer_service_fee_ |
| Language variables | kv_buyer_service_fee.* |
| CSS scope | .kv-bsf-* |
| PHP namespace | Tygh\Addons\KvBuyerServiceFee |
| Editions | Multi-Vendor only (core_edition MULTIVENDOR) |
How the fee stays out of vendor money
Section titled “How the fee stays out of vendor money”Vendor income is SUM(order_amount) - SUM(commission_amount); marketplace income is SUM(marketplace_profit) (vendor_plans). The fee is part of the order total, so the add-on treats it like the core payment surcharge:
vendor_payout_details_builder_create_details_postaddskv_bsf_gross(fee incl. added tax) andkv_bsf_taxto the payout details. An order change is stored as a difference of these components.vendor_plans_calculate_commission_for_payout_beforeaddskv_bsf_grossto$surcharge_from_total(out of the percent base) and$surcharge_to_commission(whole into the commission), and takeskv_bsf_taxout of$taxesand$vendor_taxes. Payouts of typeorder_refundedare not touched.mve_place_orderandmve_update_order(priority after vendor_plans) lowerorder_amountby the fee when no commission was calculated for the payout (vendor without a plan).- The stored fee is written in
create_order_details_post, which fires beforeplace_order, where core builds the payout. - Checkout mode: the fee is calculated on the parent cart;
place_suborders(after each vendor cart was calculated) adds the share of that vendor order to its cart, so every payout row has its own fee.
The parent order of a split cart never has a payout row. See notes/DESIGN.md of the source for the core file and line evidence.
Cart and order data
Section titled “Cart and order data”calculate_cart_postsets$cart['kv_bsf'](label,net,tax,tax_added,gross,base,mode,rule_id,rule_name,targets) and$cart['kv_bsf_total'], and addsgrossto$cart['total']. The key is always reset first.- The fee tax is stored in
$cart['taxes'][<tax id>]['applies']['KVBSF'](and['applies']['items']['KVBSF']['fee']with the subtotal method). Add-ons that read only theP,S,PSkeys ofappliesdo not see it; its amount is insidetax_subtotal. get_order_infoaddsorder['kv_bsf'](label,net,tax,tax_added,gross,base,rule_id,rule_name,level,mode,company_id,status,refunded_amount,refunded_at).levelisO(solo order that carries the whole checkout fee),V(fee, or share of the checkout fee, of one vendor order) orT(informational total on the parent order; core redirects parent order pages to the vendor orders). The field is part ofGET /api/orders/<id>.- Document variable
kvbsf(label,amount) is used by the fee row the add-on inserts into the invoice and order summary documents (after the payment surcharge row; removed on uninstall).
REST API
Section titled “REST API”GET /api/kv_buyer_fees?time_from=&time_to=&group=day|month|year|vendor|all&orders=earned|all returns the fee revenue rows and totals. GET /api/kv_buyer_fees/<order_id> returns the fee of one order. Read only; needs the view_orders privilege; a vendor administrator gets 403.
Hooks used
Section titled “Hooks used”PHP: calculate_cart_post, place_suborders, create_order_details_post, get_order_info, change_order_status, delete_order, vendor_payout_details_builder_create_details_post, vendor_plans_calculate_commission_for_payout_before, mve_place_order, mve_update_order.
Template: checkout:checkout_totals, checkout:summary, orders:order_total (storefront), orders:totals_content (admin), products:prices_block (note).
Hooks provided
Section titled “Hooks provided”None.
Database tables
Section titled “Database tables”| Table | Content |
|---|---|
?:kv_bsf_rules |
Fee rules (percent, fixed, min / max, filters, position, status). |
?:kv_bsf_orders |
One row per order that carries a fee: level, amounts, rule snapshot (rule_json), refund state. Kept on uninstall unless “Delete all data on uninstall” is on. |
Template overrides
Section titled “Template overrides”Storefront templates live in design/themes/<theme>/templates/addons/kv_buyer_service_fee/hooks/. To customize one, copy it to your own theme’s folder; do not edit the add-on’s files, they are replaced on update.