Implementing Product Import from 1C (CommerceML/XML)
Data exchange between 1C and website is one of the most in-demand and technically ambiguous tasks in web development. CommerceML standard exists since 2000s, but each 1C configuration implements it differently: XML structure, field population, category export logic, attributes vary. No universal solution exists — integration needed for specific configuration.
CommerceML Standard
1C exports data in ZIP archives with XML files:
import.zip
├── import.xml — product catalog, categories, properties
├── offers.xml — warehouses, prices, stock
└── import0.xml — catalog continuation (when split into files)
Structure example:
<?xml version="1.0" encoding="UTF-8"?>
<КоммерческаяИнформация ВерсияСхемы="2.10">
<Каталог>
<Группы>
<Группа>
<Ид>f47ac10b-58cc-4372-a567-0e02b2c3d479</Ид>
<Наименование>Электроника</Наименование>
</Группа>
</Группы>
<Товары>
<Товар>
<Ид>550e8400-e29b-41d4-a716-446655440000</Ид>
<Артикул>IPH-15-PRO-256</Артикул>
<Наименование>iPhone 15 Pro 256GB</Наименование>
</Товар>
</Товары>
</Каталог>
</КоммерческаяИнформация>
Exchange Protocol
1C initiates exchange via HTTP requests to site. Site implements handler on specific URLs:
GET /1c-exchange/?type=catalog&mode=checkauth
GET /1c-exchange/?type=catalog&mode=init
POST /1c-exchange/?type=catalog&mode=file&filename=import.zip
GET /1c-exchange/?type=catalog&mode=import&filename=import.xml
Sequence:
-
checkauth— 1C checks authorization -
init— gets limits (max file size, zip or not) -
file— uploads XML files -
import— requests import of specific file
Handler Implementation (PHP/Laravel)
class OnecExchangeController extends Controller
{
public function handle(Request $request)
{
$mode = $request->query('mode');
return match($mode) {
'checkauth' => $this->checkAuth($request),
'init' => $this->init(),
'file' => $this->uploadFile($request),
'import' => $this->importFile($request),
default => response('failure', 400),
};
}
private function checkAuth(Request $request): Response
{
if (!$this->validateCredentials($request)) {
return response("failure\nInvalid login or password");
}
$cookie = Str::random(32);
Cache::put("1c_session_{$cookie}", true, 600);
return response("success\nCOOKIE\n1c_session={$cookie}");
}
private function init(): Response
{
return response(implode("\n", [
'zip=yes',
'file_limit=' . (32 * 1024 * 1024),
]));
}
private function uploadFile(Request $request): Response
{
$filename = $request->query('filename');
$request->file('file')->storeAs('1c-exchange', $filename);
return response('success');
}
private function importFile(Request $request): Response
{
$filename = $request->query('filename');
ImportFrom1cJob::dispatch($filename);
return response('success');
}
}
XML Parsing
class CommerceMLParser
{
public function parseImport(string $xmlPath): void
{
$xml = simplexml_load_file($xmlPath, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach ($xml->Каталог->Товары->Товар as $item) {
$guid = (string) $item->Ид;
$sku = (string) $item->Артикул;
$name = (string) $item->Наименование;
Product::updateOrCreate(
['onec_guid' => $guid],
['sku' => $sku, 'name' => $name]
);
}
}
}
Offers Processing (Prices and Stock)
public function parseOffers(string $xmlPath): void
{
$xml = simplexml_load_file($xmlPath);
foreach ($xml->ПакетПредложений->Предложения->Предложение as $offer) {
$guid = (string) $offer->Ид;
$price = (float) $offer->Цены->Цена->ЦенаЗаЕдиницу;
$stock = (int) $offer->Количество;
Product::where('onec_guid', $guid)->update([
'price' => $price,
'stock' => $stock,
]);
}
}
Asynchronous Import
Large catalogs (10,000+ products) cannot be processed synchronously — 1C waits several seconds for response. Solution:
- File saved immediately (
uploadFile) -
importFilereturnssuccessimmediately - Processing runs in background via Laravel Queue
- Progress available via separate endpoint
Timeline
Product import from one 1C configuration (catalog + prices + stock): 8–12 work days. Includes testing on real customer data and debugging edge cases.







