Skip to content

Developer notes

Overview · Installation · Configuration · Usage · FAQ

The seller of a listing is the product’s company_id: the vendor in Multi-Vendor, the storefront company in Ultimate, 0 in a single store. Every panel read and write passes the acting company (runtime.company_id) to the model classes. A scope above zero sees only its own rows: Leads::get/search/counts/setStatus/reply/delete and Reports::get/search/counts/decide add company_id = scope to the query, so forged ids in a request reach nothing. Scope 0 is the marketplace owner or the all-stores administrator. The vendor permission schema lists only kv_cal_leads and kv_cal_settings; kv_cal_reports and kv_cal_cron are refused for vendors there and again in their controllers.

Table Content
sellers company_id, phone, whatsapp, show_phone, show_whatsapp, notify, notify_email
leads lead_id, company_id, product_id, user_id, name, email, message, status N/A/S, product_name (snapshot), reply, replied_at, replied_by, ip_hash, lang_code
reveals company_id, product_id, user_id, ip_hash, consent, created_at (the “numbers shown” counter)
rate bucket (hash of scope, visitor key, window), hits, window_start, expires_at (fixed-window rate limit, one atomic upsert)
searches user_id, company_id (Ultimate storefront), name, params (JSON filter set), params_hash, frequency D/W, status, last_run_at, last_sent_at, sent_count
reports product_id, company_id, user_id, product_name, url, reason, explanation, good_faith, reporter_name, reporter_email, status N/R/A/D, decision_note, decided_at, decided_by, notified_at
report_log report_id, user_id, event, note, created_at

IP addresses are stored only as HMAC-SHA256(ip) keyed from the store’s crypt_key.

Dispatch Method Purpose
kv_cal.message, kv_cal.send GET (AJAX) / POST Message form and sending. A non-AJAX GET redirects to the product page.
kv_cal.report, kv_cal.send_report GET (AJAX) / POST Report form and sending.
kv_cal.reveal POST, JSON product_id, consent=Y. Returns ok, phone, tel, whatsapp_url or error + message. GET answers 405.
kv_cal.save_search GET / POST Save the filters of the page in return_url. Guests are sent to sign in.
kv_cal.searches, kv_cal.delete_search, kv_cal.set_frequency GET / POST The account page.
kv_cal.unsubscribe GET (confirm) / POST Token link from the alert e-mail (search_id, token).

None of these dispatches is cacheable by the 4.21 full page cache. The product page output (products:product_detail_bottom.post) and the save-search bar (categories:view.pre, products:search_results_mainbox_title.pre) are catalogue data only, identical for every visitor; the account links use profiles:my_account_menu.post and profiles:account_update.post. Block caches of product blocks get the kv_cal_sellers table as an update handler and a cache-key part for the licence and display settings (schemas/block_manager/).

Forms are protected by a hidden honeypot (kv_cal_website), a signed form-time token (kv_cal_t, <unix time>.<hmac>, no session) and rate limits (Guard::hit).

AJAX forms follow the core convention: the result container is <div id="X">…<!--X--></div> with only the id attribute on the opening tag.

Template helpers (usable as Smarty modifiers)

Section titled “Template helpers (usable as Smarty modifiers)”
  • {$p = $product.product_id|fn_kv_contact_alerts_panel} returns the panel data (never the phone number).
  • {$f = ""|fn_kv_contact_alerts_features} returns ['on' => bool, 'searches' => bool].

fn_kv_contact_alerts_kv_captcha_pro_get_forms(&$forms) answers Captcha Pro’s hook kv_captcha_pro_get_forms with the forms kv_cal_message (kv_cal.send), kv_cal_report (kv_cal.send_report) and kv_cal_reveal (kv_cal.reveal). The install function also stores them with fn_kv_captcha_pro_register_form() when that function exists. Nothing is called when Captcha Pro is absent.

Mail::send($template, $to, $data, $lang, $extra) uses Tygh::$app['mailer'] and the Twig templates from the database (kv_contact_alerts_lead|reply|digest|report_new|report_decision), valid in Twig 2.14 and 3.11 (no spaceless, no filter tag, no truncate). from is company_users_department (customers) or default_company_site_administrator (staff); the reply-to of a lead e-mail is the buyer, of a reply the seller.

Test seam: when config.local.php sets $config['kv_contact_alerts_mail_log'] = '/path/file.jsonl', Mail::send() appends one JSON line (template, recipient, reply-to, data) and sends nothing. Use it only on development stores.

Digest::run($limit, $now, $dry): takes GET_LOCK('kv_cal_digest', 0), selects due searches, matches new listings with fn_get_products as an anonymous storefront visitor (listing timestamp greater than the search’s last_sent_at), claims the search with UPDATE … SET last_run_at = now, last_sent_at = now WHERE search_id = ? AND last_run_at = old and sends only when ROW_COUNT() = 1. A failed send gives the claim back. A search without new listings only moves last_run_at.

delete_company (removes the vendor’s leads, reveals and settings), post_delete_user (removes saved searches, unlinks leads and reports), kv_captcha_pro_get_forms, and the template hooks above. No core files are changed.

Path Purpose
Tygh/Addons/KvContactAlerts/Config.php, Guard.php, Mail.php Settings and licence gate, spam control, e-mail
Sellers.php, Leads.php, Reveal.php, Reports.php, Searches.php, Digest.php Domain classes
controllers/frontend/kv_cal.php Storefront endpoints
controllers/backend/kv_cal_leads.php, kv_cal_settings.php, kv_cal_reports.php, kv_cal_cron.php Panels and cron
schemas/ Menu, permissions (admin, vendor), block cache
License/, Upgrade/Synchronizer.php Licence check and self-healing upgrades (generated)
  • Reply limits. A reply goes through the store mail flow to the address typed in the lead form, so it is limited: 3 replies per lead, 60 seconds between them, no more links than the link limit, 50 replies per seller and day and 5 per buyer address and day. A seller cannot use the store as a mail relay for more than that.
  • Visitor address. Config::visitorIp() is REMOTE_ADDR; X-Forwarded-For counts only from a trusted proxy (setting), IPv6 is grouped by /64. Every rate bucket and every stored ip_hash uses it.
  • Reveal. Hourly and daily buckets per address and per signed-in customer; a repeated click on the same listing the same day does not use the quota again (and has its own cap of 30).
  • GDPR. schemas/gdpr/user_data.post.php lets the core GDPR add-on export and anonymise leads (name, e-mail, message, reply; found by account or e-mail), reports (name, e-mail) and delete saved searches. Deleting a customer account deletes the saved searches and blanks name, e-mail and text of that customer’s leads and reports. Kept: the reveal log (no personal data, address only as a hash), report decision notes and history, and leads of guests who never asked for erasure.
  • Alerts and crashes. An alert is claimed before it is sent, so it is never sent twice; if the process dies between the claim and the send, that search skips one digest. The mailer of CS-Cart has no custom header API, so the alert has no List-Unsubscribe header; it carries a visible stop link.