- THE PROBLEM
- An OpenCart database export with products, descriptions, option values, price adjustments, fitments and images spread across many tables — around two thousand products, far too many to convert in a single request.
- CONSTRAINTS
- A PHP request can time out, a browser can resend a request, and two tabs can run at once. The source is an export file read as text, not a live database.
- THE APPROACH
- Stream the dump through a tuple parser, process one product per request from a server-side queue, prepare the next 25 products in one pass, then import, map, audit media and checkpoint.
- THE RESULT
- In one documented run, 2,039 products were imported with no product failures. The admin screens from that run list 70 brands, 822 models and 249 normalised option values.
- HONEST LIMITS
- A successful product import didn’t mean every image existed: some historical gallery references were missing at the source, so the plugin reports them rather than hiding them. The mapping is written for this store’s option structure, it isn’t a general-purpose migrator, and the new storefront isn’t launched yet.
The OpenCart export is read line by line; only the tables the importer asks for are parsed, with a quote- and escape-aware tuple parser. Nothing in the file is executed.
IN THE CODEscan() · parse_tuples()
THE RECORDINSERT INTO `oc_product` VALUES (1001,'SAMPLE-1001',…)
Active products are listed into a queue. Progress is a cursor the server owns — not something the browser has to remember.
IN THE CODEindex_catalog()
THE RECORDqueue[412] → legacy_id 1001
One pass over the dump gathers the rows for the next 25 products. Each product becomes a small JSON file in a folder tied to that exact export.
IN THE CODEbuild_product_cache_chunk()
THE RECORD1001.json { product, options, fitments, images }
The product is saved as a draft. Option values are matched to normalised groups, OpenCart’s price prefixes become signed adjustments, and fitments and option rules are rebuilt instead of appended.
IN THE CODEimport_product() · map()
THE RECORDlegacy 1001 → draft product · options mapped
Images are fetched and attached. Failures are remembered and classified, and references that no longer exist at the source are reported instead of silently dropped.
IN THE CODEimport_product_media()
THE RECORDimages attached · missing references reported
The cursor advances and state is saved after each product. A replayed request is ignored, a lock keeps one worker active, and finished products are skipped on a re-run.
IN THE CODEprocess_bulk_one()
THE RECORDcursor 412 → 413 · state saved