Developer notes
Technical reference for developers who customize Store Migration Importer.
Add-on identity
Section titled “Add-on identity”| Item | Value |
|---|---|
| Add-on id | kv_store_migration_importer |
| Function prefix | fn_kv_store_migration_importer_ |
| Language variables | kv_store_migration_importer.* |
| CSS scope | .kv-smi |
| PHP namespace | Tygh\Addons\KvStoreMigrationImporter |
| Table prefix | ?:kv_smi_ |
| Editions | CS-Cart, CS-Cart Ultimate, Multi-Vendor, Multi-Vendor Ultimate (4.17.2 to 4.22.x) |
Hooks used
Section titled “Hooks used”PHP: mailer_send_pre only. While a migration worker runs (Registry runtime.kv_smi_running) the handler empties the recipient lists of any e-mail the core or another add-on tries to send, so a migration never mails anybody.
All writes go through the core functions, so the hooks of other add-ons run as they do for an administrator: fn_update_category(), fn_update_product() (features, prices, SEO name, image pairs), fn_update_product_feature(), fn_add_feature_variant(), fn_update_image_pairs(), fn_update_user() (with notify_user = false), fn_seo_update_redirect(), the Product variations service (createGroup(), attachProductsToGroup()). Imported orders and reviews are written directly (see below).
Hooks provided
Section titled “Hooks provided”None.
Database tables
Section titled “Database tables”| Table | Contents |
|---|---|
?:kv_smi_jobs |
One row per migration: source, source key, store label, sealed credentials (AES-256-GCM, key derived from the store’s crypt key), configuration (entities, options, category map, status map), state (N connected, V previewing, D preview ready, Q queued, R running, P paused, C completed, F failed, X cancelled, B rolling back, U rolled back), dry-run flag, phase, source cursor, counters, preview sample, worker lease, retry_at |
?:kv_smi_map |
The id map: source key + entity + source id to the CS-Cart id, payload hash (what a re-run compares), origin (C created by the job, A adopted, P pending) and the job that created the object |
?:kv_smi_log |
Job log: level, entity, source id, code, short detail. Codes and ids only; e-mail addresses and long digit runs are scrubbed |
?:kv_smi_images |
Image address hashes per CS-Cart object (an image downloaded before is not downloaded again) |
Uninstall keeps these tables and the settings by default (kv retention, root checkbox “Permanently delete all migration data on uninstall”). The sealed credentials are wiped from kept jobs either way.
How a migration runs
Section titled “How a migration runs”- Connect (
Jobs::connect): the form is validated, the source is called once (SourceInterface::test), the job is created with sealed credentials. The target company (vendor or storefront) is checked against?:companies. - Dry run (
Jobs::start($id, true)): each entity is read in small samples (plain queries, no bulk file), passed through the writers with the dry flag (they decide created / updated / unchanged and collect warnings, they write nothing), and the preview (counts, 8 sample rows per entity, the source category list, the order statuses seen) is stored in the job. Customer e-mail addresses are masked in the preview. - Import (
Jobs::start($id, false)): entities in the order categories, products, customers, orders, reviews.Jobs::work()claims the job with one atomicUPDATE(a lease that expires after 120 s), loops pages within a time budget (25 s by default,$config['kv_smi_budget']), saves the phase, cursor and counters after every page, and releases the lease. The page that was in flight when a worker died is read again; the id map makes that harmless. - Pauses:
RateLimitException(HTTP 429, ShopifyTHROTTLED, BigCommerceX-Rate-Limit-Time-Reset-Ms) sets state P andretry_at; a Shopify bulk operation that is still running does the same; network errors pause with 1, 2, 3, 4, 5 minutes and fail the job after the fifth in a row. A permanent error of one entity (missing scope, not found) is logged and the entity is skipped; a rejected token or a failing categories / products entity fails the job. - Cron:
php admin.php --dispatch=kv_store_migration_importer.cron --key=<key>oradmin.php?dispatch=kv_store_migration_importer.cron&key=<key>(JSON, never cached; the HTTP form needs no login becauseschemas/permissions/trusted_controllers.post.phplets the mode through and the key is checked withhash_equals) picks up due jobs. Both run in the administrator area (AREA A): there is no storefront cron address, sofn_update_user()/fn_update_product()never take their storefront-area branches (customer approval status D,profile.addedmail, vendor premoderation).Customers::save()additionally forces the status of a created customer to A. The job page runs the queue itself throughkv_store_migration_importer.run(POST, JSON) while it is open. - Rollback (
Rollback): removes exactly the objects whose map row has origin C and the job’s id: reviews, orders (no stock restore), redirects, customers without other orders, products (corefn_delete_product()), features still unused, categories without products or sub-categories. Adopted objects and objects of earlier jobs are never touched.
Security model
Section titled “Security model”-
Ultimate store-bound administrators.
Access::boundCompany()is the company of the signed-in user (auth.company_id, Ultimate only). Every controller mode that takes ajob_idgoes throughAccess::canJob()(denied answer, nothing read or changed);Jobs::listing(),Access::targets()/validTarget()(0 means the own store) andJobs::categoryChoices()/Jobs::sanitizeConfig()(Access::categoryAllowed(): own or shared with the store throughult_objects_sharing) are filtered the same way.vendor_ultimate.post.phpcloses the queue-wide cron mode to store-bound administrators. Test:tests/e2e/ult.mjs(two stores, denied + data unchanged). -
Privileges. The permission schema asks
view_catalog/manage_catalog; the controller addsmanage_usersfor jobs that migrate customers andedit_orderfor orders (delete_ordersfor their rollback) throughAccess::missingPrivileges()on start, run, resume and rollback. -
No e-mail from a job.
Jobs::work()setsruntime.kv_smi_runningfor one worker call. Hookmailer_create_message_before(array messages:toemptied,Mailer::send()returns false before any transport) and hookmailer_send_pre(readyMessageobjects: To / Cc / Bcc are protected without setters, so they are reset through a bound closure,Cs::clearRecipients()) - same signatures in 4.17.2 and 4.21.2 (Mailer.php:218/:240). Test:e2e.mjsruns a local SMTP sink and compares plain and in-job sends. -
Imported HTML goes through
SecurityHelper::sanitizeHtml()(HTMLPurifier, the core’s own sanitizer for vendor input) when the option “Clean product and category descriptions” is on (default) and always for Multi-Vendor imports into a vendor; where that class does not exist a plain filter removes script, iframe, object, embed, style, event attributes and javascript: addresses. -
Imported orders and stock. Orders carry the
[kv-smi:marker;update_product_amount_before_tracking_checkingturns the stock change of such an order into 0, so a later status change never restocks goods the import did not take. Vendor payouts are written byfn_mve_place_order()/fn_mve_update_order(), not by status changes, and an imported order has no payout row;direct_paymentsreturns early for it. -
Known limits of a rollback. Feature variants added to a feature that already existed before the job are not removed; an adopted product that was rewritten (option “Update existing products with the same SKU”) is released, not restored.
Idempotency
Section titled “Idempotency”- Every object has a map row keyed by the source (platform + store address) and the target vendor or store, not by the job (the same source migrated into two stores has two separate maps, so one store’s job can never update the other store’s objects). A pending row (origin P) is written before the CS-Cart object is created; if the worker dies in between, the next run finds the object by its natural key (SKU for products of a pending row, but only a product written at or after the time the pending row was opened and not mapped to another source id, so an older merchant product is never taken over, name + parent for categories, e-mail for customers, the
[kv-smi:<source>:<id>]marker in the staff notes of an order, product + date + author for reviews) and adopts it. - A re-run compares the hash of the normalised source record (plus a fingerprint of the options) with the stored one: unchanged records are skipped, changed ones update the imported copy (option “Update objects imported before”).
- An existing product with the same SKU is never overwritten unless the option “Update existing products with the same SKU” is on.
Source drivers
Section titled “Source drivers”Source\SourceInterface (supports(), test(), page($entity, $cursor, $limit, $opts), orderStatuses()), implemented by Source\Shopify, Source\WooCommerce, Source\BigCommerce. A driver returns normalised records (documented in the interface); the writers know nothing about the platform. To add a source: implement the interface, register it in Source\Factory and Config::SOURCES, add the connection form fields to new.tpl and Jobs::connect(), and test it with a mock built from the platform’s documentation (tests/mock).
Test switches (config.local.php, never panel settings): $config['kv_smi_allow_private'] = true lets the clients reach 127.0.0.1 over plain http; $config['kv_smi_base_url_shopify' | '_woocommerce' | '_bigcommerce'] point a driver at a mock server. Without the first switch every request needs https and a public address (UrlGuard, connection pinned to the checked address, no redirects for API calls, at most 3 for downloads, no proxy).
Official documentation used
Section titled “Official documentation used”Every field name the drivers read comes from these pages (fetched 2026-11-26). Items marked UNVERIFIED were not confirmed by the fetched page text; the drivers treat them as optional (a missing field is a warning for that record, never a crash) and the listing makes no promise about them.
Shopify (Admin GraphQL API, version setting default 2026-10)
Section titled “Shopify (Admin GraphQL API, version setting default 2026-10)”Authentication (fetched 2026-11-26 from shopify.dev):
| Topic | Page | Verified | UNVERIFIED |
|---|---|---|---|
| Client credentials grant for apps created in the Dev Dashboard | https://shopify.dev/docs/apps/build/authentication-authorization/access-tokens/client-credentials-grant | POST https://{shop}.myshopify.com/admin/oauth/access_token, Content-Type: application/x-www-form-urlencoded, body grant_type=client_credentials, client_id, client_secret (no scope); answer access_token, scope, expires_in (always 86399); token sent as X-Shopify-Access-Token; works only when app and store belong to the same organization and the app is installed; client id / secret from Dev Dashboard > app > Settings; error shop_not_permitted (“Client credentials cannot be performed on this shop”) |
the HTTP status and JSON body of the error answers (the page does not list them; the driver treats 400 / 401 / 403 / 404 of the token endpoint as “no token” and shows one message) |
| Admin-created (legacy) custom apps | https://shopify.dev/docs/apps/build/authentication-authorization/access-tokens/generate-app-access-tokens-admin | “you can no longer create new admin-created custom apps”; their Admin API access token “doesn’t expire”; an app moved to the Dev Dashboard keeps its token and scopes; read_all_orders is in the Admin API scope table |
the date (the page names none; Shopify community announcements say 2026-01-01) |
| API versions | https://shopify.dev/docs/api/usage/versioning | stable 2026-01, 2026-04, 2026-07, 2026-10 (latest stable); each stable version supported at least 12 months | whether every field read here is unchanged in 2026-10: the 2026-10 changelog entries found remove nothing the drivers read (ProductVariant.barcode deprecated: not read; displayFulfillmentStatus may return FULFILLMENT_NOT_REQUIRED: such an order is mapped by its financial status) |
The driver stores client_id + client_secret sealed with the job, keeps the current token and token_expires there too, renews the token 120 seconds before it expires and once when Shopify answers 401, and saves the new token through SourceInterface::onCredentials().
Fields:
| Topic | Page | Verified | UNVERIFIED |
|---|---|---|---|
Bulk operations: bulkOperationRunQuery, polling bulkOperation(id:) (API 2026-01+) / currentBulkOperation (earlier), url / partialDataUrl (expire after one week), JSONL with __parentId, status values CREATED RUNNING COMPLETED FAILED CANCELED, error codes, limits (5 connections, 2 nesting levels, concurrency by version) |
https://shopify.dev/docs/api/usage/bulk-operations/queries | all of it | that a child line’s connection is told apart by the type in its id (our reading of the format; the page does not say how to tell connections apart, so ProductVariant, Media*, Collection and LineItem ids are matched) |
| Product | https://shopify.dev/docs/api/admin-graphql/latest/objects/Product | id, title, handle, descriptionHtml, vendor, productType, tags, status, seo, options, variants, media, collections, onlineStoreUrl, createdAt |
subfields seo { title description }, options { name values }, media node ... on MediaImage { id alt image { url } } |
| ProductVariant | https://shopify.dev/docs/api/admin-graphql/latest/objects/ProductVariant | id, sku, price, compareAtPrice, inventoryQuantity, selectedOptions, media, inventoryItem, position, title (barcode and image are deprecated on that page and are not read) |
selectedOptions { name value } |
| InventoryItem | https://shopify.dev/docs/api/admin-graphql/latest/objects/InventoryItem | measurement (InventoryItemMeasurement) |
measurement { weight { value unit } } and the units KILOGRAMS GRAMS POUNDS OUNCES |
| Customer | https://shopify.dev/docs/api/admin-graphql/latest/objects/Customer | id, firstName, lastName, createdAt, defaultAddress; scope read_customers; email and phone exist but are marked deprecated (still read; the API version setting is the escape hatch if Shopify removes them) |
defaultEmailAddress / defaultPhoneNumber shapes (not used) |
| MailingAddress | https://shopify.dev/docs/api/admin-graphql/latest/objects/MailingAddress | firstName, lastName, company, address1, address2, city, province, provinceCode, zip, countryCodeV2, phone |
none |
| Order | https://shopify.dev/docs/api/admin-graphql/latest/objects/Order | name, email, createdAt, cancelledAt, note, currencyCode, displayFinancialStatus, displayFulfillmentStatus, paymentGatewayNames, subtotalPriceSet, totalPriceSet, totalShippingPriceSet, totalTaxSet, totalDiscountsSet, customer, shippingLine, billingAddress, shippingAddress, lineItems. “Only the last 60 days’ worth of orders from a store are accessible from the Order object by default”; older orders need an app that is granted read_all_orders |
shopMoney { amount } of the MoneyBag, lineItems node fields (title, sku, quantity, originalUnitPriceSet, variant { id product { id } }) |
| Collection | https://shopify.dev/docs/api/admin-graphql/latest/objects/Collection | id, handle, title, descriptionHtml, sortOrder, image |
image { url }; the root count fields productsCount, customersCount, ordersCount, collectionsCount (used only for the “found” figures; a failure there is ignored) |
Shopify collections are flat (no hierarchy) and Shopify has no review data in the Admin API, so categories are flat from Shopify and reviews are not available from Shopify.
WooCommerce (REST API v3)
Section titled “WooCommerce (REST API v3)”Page: https://woocommerce.github.io/woocommerce-rest-api-docs/
| Topic | Verified | UNVERIFIED |
|---|---|---|
| Authentication | HTTPS Basic with the consumer key as user name and the consumer secret as password; query-string fallback (not used: secrets in URLs end up in logs); plain http needs OAuth 1.0a (not supported, https is required) | |
| Pagination | page, per_page (default 10), offset, headers X-WP-Total, X-WP-TotalPages, Link |
the maximum of per_page (the page does not state it; the driver asks for 100) |
| Customers | /customers: email, first_name, last_name, username, billing, shipping, meta_data |
date_created_gmt, role in responses |
| Orders | /orders: status values pending processing on-hold completed cancelled refunded failed (any in the list filter); customer_id, customer_note, billing, shipping, payment_method_title, line_items (id, name, product_id, variation_id, quantity, sku, price, subtotal, total), shipping_lines (method_title, total) |
response fields number, date_created_gmt, total, total_tax, shipping_total, discount_total |
| Products | type (simple, grouped, external, variable), status, description, short_description, sku, regular_price, sale_price, manage_stock, stock_quantity, weight, categories, tags, images (id, src, name, alt, position), attributes (id, name, position, visible, variation, options), default_attributes, slug |
response fields price, permalink, stock_status, variations |
| Product variations | the whole resource /products/<id>/variations and its fields (id, sku, price, regular_price, sale_price, manage_stock, stock_quantity, stock_status, weight, image, attributes[] {name, option}); the page text fetched did not contain this section |
|
| Categories | id, name, slug, parent, description, image, menu_order |
the old address of a category (built as /product-category/<slug chain>, WooCommerce’s default permalink base) |
| Reviews | /products/reviews: product_id, review, rating, date_created, date_created_gmt |
status, reviewer, reviewer_email (the fetched text showed name and email in the create arguments; the driver reads both spellings) |
| Currency | /data/currencies/current (only used to show the currency in the job header; a failure is ignored) |
BigCommerce (Catalog v3, Customers v3, Orders v2)
Section titled “BigCommerce (Catalog v3, Customers v3, Orders v2)”| Topic | Page | Verified | UNVERIFIED |
|---|---|---|---|
| Products | https://docs.bigcommerce.com/developer/api-reference/rest/admin/catalog/products/get-products | GET /stores/{store_hash}/v3/catalog/products, header X-Auth-Token, include (images, custom_fields, variants, options, modifiers, primary_image; options limits a page to 10), page, limit (default 50), meta.pagination (total, count, per_page, current_page, total_pages), product fields id, name, type, sku, description, weight, price, sale_price, retail_price, categories, brand_id, inventory_level, is_visible, availability, custom_url (url, is_customized), page_title, meta_description, date_created, images[] (url_zoom, url_standard, is_thumbnail, sort_order, description), custom_fields[] |
the product schema did not define variants[]: id, sku, price, sale_price, weight, inventory_level, image_url, upc, option_values[] {option_display_name, label}; inventory_tracking; the maximum of limit (the driver asks for 25 with includes) |
| Categories | https://docs.bigcommerce.com/developer/api-reference/rest/admin/catalog/categories/get-categories | GET /v3/catalog/categories with id, parent_id, name, description, sort_order, page_title, meta_description, image_url, is_visible, custom_url; the page recommends the Catalog Trees endpoint “when possible” (the flat list is used: it needs no tree id) |
limit 250 |
| Orders v2 | https://docs.bigcommerce.com/developer/api-reference/rest/admin/management/orders/get-orders | GET /v2/orders, page, limit (default 50), sort=id:asc, fields id, customer_id, date_created (RFC 2822, UTC), status, total_inc_tax, subtotal_ex_tax, shipping_cost_inc_tax, total_tax, discount_amount, currency_code, payment_method, customer_message, billing_address; each order links its products and shipping_addresses sub-resources (url, resource: the driver follows the resource path) |
what an empty page returns (the driver accepts 204 and an empty array), the fields of the products and shipping address sub-resources, /v2/orders/count, /v2/store (name, currency, weight_units) |
| Customers v3 | page not found by the fetcher | everything: GET /v3/customers?include=addresses, id, email, first_name, last_name, phone, company, date_created, addresses[] (address1, address2, city, state_or_province, postal_code, country_code, phone) |
|
| Brands, reviews | GET /v3/catalog/brands, GET /v3/catalog/products/{id}/reviews and their fields |
||
| Rate limits | the 429 answer with X-Rate-Limit-Time-Reset-Ms (a missing header falls back to Retry-After, then 30 s) |
Everything marked UNVERIFIED is the first thing to check against a real store; the mock servers in tests/mock are built from the documented schema field by field (with the UNVERIFIED parts built the way the platform is generally known to answer), not from a recorded session. The listing says “tested against the documented APIs”, not “tested against a live store”.
CS-Cart objects written
Section titled “CS-Cart objects written”| Source | CS-Cart | How |
|---|---|---|
| Category | category | fn_update_category(); parent first; a mapped category is not written; same name + parent is reused |
| Product with options | one product per variant + a variation group | option features (purpose = group_variation_catalog_item, selectbox) created with fn_update_product_feature() / fn_add_feature_variant(), products saved with the feature values in product_features, grouped with Service::createGroup() / attachProductsToGroup() |
| Product without options | product | fn_update_product(); price, list price (compare-at), stock (tracking B, or D when the source does not track stock), weight in the store’s weight unit, status, SEO name, page title, meta description, description, short description |
| Image | image pair | downloaded with the guarded downloader, type read from the bytes, fn_update_image_pairs(); the first image is the main image |
| Attributes, tags, product type, brand | text features | one text feature per name (existing feature of that name reused) |
| Old URL | ?:seo_redirects |
fn_seo_update_redirect(), type p or c, object id; skipped when the address equals the new one or already is a redirect |
| Customer | customer (user type C) | fn_update_user() with a random password nobody knows and notify_user = false; an existing customer with the same e-mail address is adopted |
| Order | ?:orders + ?:order_details |
direct insert with the original date, totals, addresses and the mapped status; staff notes carry the marker and the source facts; no stock change, no hooks of the order workflow |
| Review | ?:product_reviews |
direct insert with rating, text, author and date on the first variation of the product; actualizeProductPreparedData() refreshes the rating cache |
Order amounts are stored as imported, without currency conversion (CS-Cart orders have no currency column); the source currency is written into the staff notes.
php81 tests/unit.php and php83 tests/unit.php (offline: URL guard, secrets, time stamps, the three drivers against the fixtures, the Shopify bulk file assembly, status maps); node tests/e2e/e2e.mjs --store <cs417*|mv417*> --port <port> drives the real admin pages and the queue against tests/mock/server.mjs (the suite refuses to run unless the store is a local pool store and every API address is 127.0.0.1); tests/lifecycle.sh; kv qa lic. Fixtures: node tests/mock/dump.mjs regenerates tests/fixtures/ from the mock.