Custom product export: CSV, Excel, XML, JSON for any requirement
Recently, a client came to us: an online store with 50,000 products. Marketplaces demanded XML and CSV in different formats, accounting needed Excel for 1C, and analysts wanted JSON. Each time developers wrote a new script, spending days. Field mapping errors caused the price without VAT to be sent to Wildberries. This is a typical situation for a growing business when departments request different formats and there's no unified solution.
We proposed a single architecture — the Builder + Writer pattern. It covers all scenarios without code duplication. Now the client selects an export template from the admin panel, clicks "Download", and gets the needed file format in seconds.
Why flexible export is complex?
- Different formats: CSV doesn't support nested data, XML is standard for 1C and marketplaces, JSON is convenient for APIs, but for sizes >50 MB NDJSON is better.
- Each recipient wants their own set of fields: for Yandex.Market you need SKU, name, price, stock; for Instagram only photo and link.
- Data volume: a catalog can grow to hundreds of thousands of items. A simple
json_encodeinto memory will crash the server.
How does async export work?
For large catalogs, export runs in the background via a queue. A job receives the template configuration, iterates through products in chunks of 1000 records, and passes them to the Writer. The user gets a notification when the file is ready. This avoids blocking the site and allows exporting even millions of products.
How we build export: Builder + Writer pattern
We separated data formation logic (Builder) and file writing (Writer). The Builder receives a chain of methods for configuring fields and filters, then iterates through the database in chunks and passes rows to the Writer.
interface ExportWriterInterface { public function open(string $filePath): void; public function writeHeader(array $columns): void; public function writeRow(array $row): void; public function close(): string; // returns file path } The Builder stores the config and can resolve related fields (category, images, attributes) via a match expression. For CSV: we add BOM for Excel, use fputcsv with ; delimiter.
class CsvWriter implements ExportWriterInterface { private $handle; public function open(string $filePath): void { $this->handle = fopen($filePath, 'w'); fwrite($this->handle, "\xEF\xBB\xBF"); } public function writeHeader(array $columns): void { fputcsv($this->handle, $columns, ';', '"'); } public function writeRow(array $row): void { fputcsv($this->handle, $row, ';', '"'); } public function close(): string { fclose($this->handle); return $this->filePath; } } For Excel we use streaming OpenSpout — it writes rows directly into a ZIP stream, consuming ~10 MB memory regardless of file size. For large JSON volumes — NDJSON (one object per line). XML — via XMLWriter with <product> elements.
Format comparison table
| Format | Performance | File size | Nesting | Recommended volume |
|---|---|---|---|---|
| CSV | high | small | no | up to 100,000 rows |
| XLSX | medium | medium | no | up to 1,000,000 rows (with OpenSpout) |
| XML | low | large | yes | up to 50,000 products |
| JSON/NDJSON | high | medium | yes | up to 500,000 objects (NDJSON) |
Comparison of manual vs automated export
| Parameter | Manual (new script each time) | Automated (Builder + Writer) |
|---|---|---|
| Development time for new format | 1-2 days | 0 (select template) |
| Mapping errors | frequent | eliminated (single config) |
| Performance at large volume | slow, memory crash | streaming, ~10 MB |
| Adapting to new requirements | complete rewrite | add field to Builder |
Builder configuration example
$builder = new ProductExportBuilder(); $builder->addField('sku', function ($product) { return $product->sku; }) ->addField('name', function ($product) { return $product->name; }) ->addField('price', function ($product) { return round($product->price, 2); }) ->addField('category', function ($product) { return $product->category->name; }) ->filterBy('price', '>', 100) ->chunkSize(1000); What is included in the implementation
- Development of a Builder with support for custom fields, filters, and chunking (1000 records).
- Writer set for CSV (with BOM), XLSX (OpenSpout), XML, JSON (including NDJSON).
- Async export for large files: products are exported in the background via a queue, user gets notification.
- Export templates — stored in DB, can include transformations (price rounding, image cropping).
- Ready download page with access control and MIME types.
- Documentation for template setup and deployment.
How long does it take?
- Basic version (CSV + Excel + Builder with chunking) — 2 days.
- Adding XML, JSON, NDJSON and async job — +1 day.
- Templates, transformations, download — +1 day.
The final cost is calculated individually after analyzing the volume and complexity of the catalog. Contact us — we will assess your project within one business day.
Our engineers have 5+ years of experience in Laravel and PHP. We have completed 30+ export integration projects for stores with catalogs up to 500,000 products. We guarantee that the files will be compatible with 1C, your marketplaces, and BI systems. Order a turnkey solution — get flexible export that saves your developers hours.







