Developer notes
Tables
Section titled “Tables”| Table | Contents |
|---|---|
cscart_kv_vlb_scores |
The snapshot: one row per leaderboard (period, metric, category) and vendor with position, rank number, previous rank, ranked count, score, orders, display rating, reviews, products and state. Main leaderboards (category 0) of sales, orders and rating also hold unranked vendors (rank_no 0, state X excluded, P no products, O too few orders, R too few reviews). |
cscart_kv_vlb_history |
Daily rank per vendor, metric and period (180 days), for the vendor trend. |
cscart_kv_vlb_runs |
Run log and the cursor of a paused run. |
cscart_kv_vlb_stage |
Per-vendor figures of the run in progress (emptied when the run finishes). |
cscart_kv_vlb_stage_cat |
Category figures of the run in progress, one row per vendor, period and category. |
cscart_kv_vlb_scores_new |
Shadow table filled during the build phase; one RENAME TABLE puts it live. |
Ranking rules
Section titled “Ranking rules”- Sorting: score descending, then tie-breakers (sales: orders, rating; orders: sales, rating; rating: review count, orders; most improved: growth, sales), then company id. Rank numbers use standard competition ranking (1, 2, 2, 4): equal scores share a rank number, the display position stays unique.
- Rating: Bayesian average
(n / (n + m)) * average + (m / (n + m)) * marketplace mean, withm= minimum reviews. - Most improved: places gained in the sales ranking against the previous window of the same length; a vendor that was not ranked before starts below the last ranked vendor.
- Category figures: order lines whose product has its main category in the category tree, distinct orders per category, computed in SQL per category level.
- Category leaderboards keep the first 100 vendors per leaderboard.
Recompute
Section titled “Recompute”Tygh\Addons\KvVendorLeaderboards\Engine::run($trigger, $budget) has three resumable phases: collect (vendors in chunks into the stage tables; the budget is checked before every query), build (one board or one category at a time into the shadow table with REPLACE; memory is bounded by one board) and swap (an atomic RENAME TABLE). The live table is never empty or half written; a crash at any point leaves the previous snapshot and the next call resumes. Position changes compare with the newest history day before the run’s day (main boards) or carry the live row’s previous rank on the same day (category boards), so a same-day re-run gives the same result. Panel steps use 20 vendors per chunk and 8 seconds; after 3 steps without progress the panel trigger stops (“cron needed”). A MySQL named lock allows one run at a time; a run that has not moved for 6 hours is abandoned.
Console: php admin.php --dispatch=kv_vendor_leaderboards.cron.
Cache and full page cache
Section titled “Cache and full page cache”- The block reads the snapshot only; nothing depends on the visitor or the session. The block cache uses
kv_vlb_scores,companies,company_descriptions,logos,images_links,images,categories,category_descriptionsas update handlers, thecategory_idrequest parameter and a licence/settings key. - Storefront reads go through
Registry::registerCache()with these tables, so on 4.21 with the full page cache the pages get them as cache tags and are purged when a recompute writes the snapshot. - The badge data is assigned in
controllers/frontend/init.post.phpfrom a registered cache ofkv_vlb_scores, only on vendor pages, or on every page when “Badge on product cards” is on (then every page carries thekv_vlb_scorestag and each recompute purges the whole page cache once). Product list blocks getkv_vlb_scoresas an extra update handler. - Storefront rows never contain the score or the order count, and show the unique position instead of a shared rank number.
Hooks and templates
Section titled “Hooks and templates”- PHP hook:
before_dispatch(panel pseudo-cron). - Block type
kv_vendor_leaderboard, templatesaddons/kv_vendor_leaderboards/blocks/leaderboard_{cards,podium,list}.tpl, components inaddons/kv_vendor_leaderboards/components/. - Template hooks:
companies:productsandcompanies:view(pre, vendor page badge),products:product_labels(post, product card label). - Styles:
css/addons/kv_vendor_leaderboards/styles.less, scoped under.kv-vlb*. Colours are CSS custom properties on.kv-vlb, for example.kv-vlb { --kv-vlb-accent: #0a7d55; }in your theme’s custom CSS.
Permissions
Section titled “Permissions”- Administrators:
view_kv_vlb(GET) andmanage_kv_vlb(POST: recompute, exclusions). - Vendors: only
kv_vendor_leaderboards.ranking, always for their own company (thecompany_idparameter is ignored for vendors).