Developer notes
app/addons/kv_vendor_domains/ addon.xml, init.php, func.php Tygh/Addons/KvVendorDomains/ Hosts.php pure host, URL and dispatch helpers (unit-tested) Rules.php pure status rules: P/W/A/R/S/D transitions, primary host, plan limits (unit-tested) Dns.php TXT ownership + CNAME/A routing check with an injectable resolver (unit-tested) Config.php settings, main host, base domain Domains.php records, plan rules, cached host map, DNS checks, cron re-check Runtime.php vendor host recognition, routing, url_post, canonical URLs Seo.php sitemap.xml and robots.txt of a vendor host License/Client.php, License/Ed25519.php, Upgrade/Synchronizer.php (generated) controllers/backend/kv_vendor_domains.php admin and vendor pages, cron mode "recheck" controllers/backend/vendor_plans.post.php domain rule for the plan editor controllers/frontend/kv_vendor_domains_public.php to_main, robots, sitemap (vendor hosts), add (marketplace domain) schemas/{menu,permissions,block_manager}/ menu, privileges, block cache scopedesign/backend/templates/addons/kv_vendor_domains/ manage, plans, update, status component, plan editor hookvar/themes_repository/responsive/templates/addons/kv_vendor_domains/hooks/index/scripts.post.tpljs/addons/kv_vendor_domains/func.js storefront script (vendor hosts only)Database
Section titled “Database”| Table | Columns |
|---|---|
cscart_kv_vendor_domains |
domain_id, company_id, type (S subdomain, C custom), host (UNIQUE, lower case, no port), status (P pending DNS, W waiting approval, A active, R rejected, S suspended, D disabled), is_primary, token, txt_ok, route_ok, fail_count, last_check, last_detail, reason, created_at, updated_at, approved_at, approved_by |
cscart_kv_vendor_domains_plan_rules |
plan_id, allow_subdomain, allow_custom, max_domains |
Uninstall drops both tables, the two privileges and the language variables.
How a vendor host is served
Section titled “How a vendor host is served”init.phpcallsRuntime::boot(). Add-ons initialize inside CS-Cart’s init stack, after the session and before routing.boot()returns at once for the admin, the API, the console and for requests whose host equals the storefront host. Otherwise it looks the host up in the cached host map (Domains::hostMap(), Registry cache tagged with the domain, rule, company, vendor plan and settings tables), checks the license for the main host and then rewritesconfig.http_host / https_host / current_host / *_location. From here on everyfn_url()link, SEO redirect and asset URL carries the vendor host. Without this the core would 301 the request to the default storefront (fn_dispatch).get_route(priority 1900, after the SEO add-on at 1800) maps/robots.txtand/sitemap(-N).xmlto the public controller,/tocompanies.vieworcompanies.productsof the vendor, redirects other vendors’ pages and products to the same path on the marketplace, and redirects main-only dispatches. GET and HEAD get a 302; POST gets a 307 and AJAX getsforce_redirectionfrom the public controller (to_main), with the ajax parameters stripped.get_products_preforcescompany_idof the vendor in every product list on a vendor host. (categories,products.search, features, blocks.)url_post(1900): links of main-only dispatches and links that the core built for the main host with the vendor’scompany_idare rewritten (main-only to the marketplace, vendor links to the vendor host).dispatch_before_display(1900):seo_canonical,seo_alt_hreflangs_listandschema_org_markup_itemsare rewritten from the hosts of the page to the target origin (see Configuration, Canonical URLs). Thescripts.post.tplhook prints the script configuration on vendor hosts only.
Hosts are trusted only when they equal an active record exactly (case-insensitive, port ignored) of an active vendor whose plan allows the type. HTTP_HOST/X-Forwarded-Host values that match nothing are handled by the core as before.
Sessions and cookies
Section titled “Sessions and cookies”CS-Cart builds the session before add-ons initialize. Its name carries md5(http_location) of the main host and its cookie domain is derived from the main host. Consequences, and why the add-on never relies on them:
- Subdomain of the marketplace host (
acme.example.comwith the marketplace onexample.com): the cookie domain.example.comis sent to vendor subdomains, so the session may be shared. If the marketplace runs onwww.example.comthe cookie domain is.www.example.comand it is not shared. - Custom domain: the browser drops a cookie for
.example.comset byshop.acme.com; every request starts a guest session that is never reused. - Therefore everything that needs a session runs on the marketplace domain: links are rewritten, add-to-cart / wishlist / comparison buttons are re-pointed by the script (a top-level GET navigation to the marketplace, see below), and requests that still arrive on a vendor host are redirected (302, 307 for POST,
force_redirectionfor AJAX). Login, registration, checkout, payment callbacks and the account never run on a vendor host. - Add to cart. The core session cookie is
SameSite=Lax, so a cross-site POST from a vendor’s own domain would not carry it (every add would start a new guest session and replace the visitor’s cookie). The storefront script therefore takes the click over and openskv_vendor_domains_public.addon the marketplace domain with a top-level GET navigation, which carries the Lax cookie; the product form is in the query string. The endpoint adds directly only when the Referer is an active vendor host and every product belongs to that vendor (then the checks of corecheckout.addapply: anonymous shopping, only the product of the pressed button viaextra, amount 1 when empty; it adds withfn_add_product_to_cart(), recalculates with'E', saves the cart and opens the cart page). In every other case (no Referer, for example under ano-referrerpolicy, a foreign site, the marketplace host itself, or a product of another vendor) nothing is added: a confirmation page on the marketplace lists the products and amounts, and its form posts tokv_vendor_domains_public.confirm, which adds only with a session-bound token (HMAC of the session id with the store crypt key; checked by the add-on itself, so it also holds when the core storefront CSRF check is off, as with the full page cache). The visitor makes one extra click. Corecheckout.addis not used here because on 4.17 it answers AJAX requests only. The wishlist button (acm-submitlink withdata-ca-dispatch) uses the same endpoint withto=wishlist(corewishlist.addanswers POST only). Comparison links (cm-ajaxlinks toproduct_features.add_product, already pointing to the marketplace throughurl_post) would be a cross-origin XHR without the cookie, so the script opens them as a top-level navigation and lands on the marketplace comparison list. Tested in a real browser with the marketplace onlocalhostand the vendor on a.testdomain: two adds in a row, add after login, wishlist, comparison and ano-referrerpage (confirmation, then add) all stay in one session and keep the login. - Cookies written with
fn_set_cookie()(language, currency) are host-only (no domain) and therefore per vendor host. - The mini-cart block on a vendor host shows that host’s session (empty for custom domains); the cart link opens the marketplace cart.
- Consequence for CSRF: storefront POSTs do not use the security hash (
config.tweaks.anti_csrfis forced off with the full page cache).
Full page cache
Section titled “Full page cache”Untested. The points below are the design; no full page cache or Varnish run was made.
- Output of vendor hosts depends on the host only: no session or visitor data, no cookies. Varnish’s default
vcl_hashhashes URL and Host, so every host gets its own cached objects. Do not normalize or strip theHostheader in your VCL; addhash_data(req.http.host);if you replacedvcl_hash. - The public controller (
kv_vendor_domains_public) is not in the cacheable dispatch list ofschemas/full_page_cache/varnish.php; sitemap output is cached inside CS-Cart (Registry cache tagged withproducts,seo_names, …). - ESI (
esi.php) requests keep theHostof the page, so session-dependent blocks (cart_content,my_account) render for the vendor host and show a guest state on custom domains. - Cache tags: page tags come from the tables read while rendering. A domain change touches
kv_vendor_domains, which is not a global tag; pages are not affected by it, only the host map is.
Block cache
Section titled “Block cache”The core’s block cache key has no host. On a vendor host blocks list only that vendor’s products and carry the host in their links, so schemas/block_manager/block_cache_properties.post.php adds the callable handler fn_kv_vendor_domains_scope_key ('' on the marketplace host, h<host> on a vendor host) to the key of every cached block, and kv_vendor_domains to the update handlers (adding, disabling or changing a domain refreshes cached blocks).
License check
Section titled “License check”Tygh\Addons\KvVendorDomains\License\Client verifies the license against the Kavio Labs license server.
- Gate:
Runtime::licensed($mainHost)(License\Client::isActive()for the marketplace host) inRuntime::boot(). Vendor hosts are covered by the marketplace license. When it is false the add-on does not recognize vendor hosts, so the core redirects them to the marketplace; sitemap and robots disappear with them. Admin and vendor pages are not gated. - State:
kv_license_kv_vendor_domains(?:storage_data), orvar/kv_storage/kv_vendor_domains/license.jsonwhile the full page cache is active, protected by an HMAC with the store’s crypt key. - Cron:
php admin.php --dispatch=kv_vendor_domains_license.check. - Development stores: the constants
KV_LICENSE_SERVER_URL,KV_LICENSE_TEST_HOST,KV_LICENSE_TEST_TIME_OFFSET(ignored on production hosts). - Admin license UI (generated): card, badge, status bar (first line of the mainbox of
manage,plansandupdate),license.less.
PHP hooks used
Section titled “PHP hooks used”| Hook | Handler | Purpose |
|---|---|---|
get_route (1900) |
fn_kv_vendor_domains_get_route |
Routing on vendor hosts |
url_post (1900) |
fn_kv_vendor_domains_url_post |
Link rewriting |
get_products_pre |
fn_kv_vendor_domains_get_products_pre |
Vendor-only product lists |
dispatch_before_display (1900) |
fn_kv_vendor_domains_dispatch_before_display |
Canonical, hreflang, JSON-LD |
vendor_plan_after_save / _after_delete |
Plan rule from the plan editor | |
delete_company |
Removes the vendor’s domains | |
init_templater_post |
Upgrade synchronizer (only while an upgrade is pending) |
Arguments are identical in 4.17.2 and 4.21.2.
Template hooks used
Section titled “Template hooks used”| Hook | Where | Purpose |
|---|---|---|
index:scripts (post) |
storefront | Script configuration on vendor hosts |
vendor_plans:update_restrictions (post) |
admin | Domain rule fields in the plan editor |
Customization tips
Section titled “Customization tips”- Controllers or dispatches that must stay on the marketplace domain are a setting, not code.
- To run DNS checks against your own resolver, set
\Tygh\Addons\KvVendorDomains\Dns::setResolver(callable $resolver)from your add-on (callable(string $name, string $type): string[], typesTXT,CNAME,A,AAAA). Domains::hostMap()returns['hosts' => host => [company_id, type], 'primary' => company_id => host, 'all' => company_id => hosts]for served domains only.
Third-party code
Section titled “Third-party code”Tygh/Addons/KvVendorDomains/License/Ed25519.php (checks the signature of the license server’s answers on servers whose PHP has no sodium extension) is derived from paragonie/sodium_compat, ISC License, Copyright (c) 2016-2023 Paragon Initiative Enterprises and Copyright (c) 2013-2019 Frank Denis. The full license notice is in the file header.
Limits
Section titled “Limits”- Vendor hosts render the default storefront (the host is unknown to the core, which falls back to it before add-ons initialize): layout, categories and currency of other storefronts on Multi-Vendor Ultimate are not used.
- Master (common) products: lists on a vendor host are limited to
company_idof the vendor; master products (company_id 0) with an offer of the vendor are not listed, and a master product page redirects to the marketplace. - Custom domains: the session cookie is not accepted there, so every request starts a guest session. 4.21 starts sessions lazily; on 4.17 and 4.18 a session row is written per request, crawlers included.
- DNS resolution uses the system resolver (
dns_get_record). A failed lookup is distinguished from a confirmed miss with a control lookup of the CNAME target (or the marketplace host).