Skip to content

Developer notes

Technical reference for developers who customize Buyer Service Fee.

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)

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_post adds kv_bsf_gross (fee incl. added tax) and kv_bsf_tax to the payout details. An order change is stored as a difference of these components.
  • vendor_plans_calculate_commission_for_payout_before adds kv_bsf_gross to $surcharge_from_total (out of the percent base) and $surcharge_to_commission (whole into the commission), and takes kv_bsf_tax out of $taxes and $vendor_taxes. Payouts of type order_refunded are not touched.
  • mve_place_order and mve_update_order (priority after vendor_plans) lower order_amount by 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 before place_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.

  • calculate_cart_post sets $cart['kv_bsf'] (label, net, tax, tax_added, gross, base, mode, rule_id, rule_name, targets) and $cart['kv_bsf_total'], and adds gross to $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 the P, S, PS keys of applies do not see it; its amount is inside tax_subtotal.
  • get_order_info adds order['kv_bsf'] (label, net, tax, tax_added, gross, base, rule_id, rule_name, level, mode, company_id, status, refunded_amount, refunded_at). level is O (solo order that carries the whole checkout fee), V (fee, or share of the checkout fee, of one vendor order) or T (informational total on the parent order; core redirects parent order pages to the vendor orders). The field is part of GET /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).

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.

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).

None.

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.

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.