Setting Up Data Matrix Marking Codes on 1C-Bitrix
Data Matrix code for marking is a two-dimensional barcode that encodes the product unit identifier (GTIN), serial number, and cryptographic element. At the Bitrix level, the task comes down to: receive codes from supplier or marking system, save in database, display on label if needed, and deduct on sale.
Structure of Data Matrix Code in Marking System
The full marking code looks like: 01 + GTIN (14 characters) + 21 + serial number (up to 20 characters) + crypto tail. Example:
0104607086000058215t2&/u+K<K)O
Decoding: 01 — application identifier (Application Identifier) for GTIN, 21 — AI for serial number. Code parsing in PHP:
function parseMarkingCode(string $code): array {
// GS1 DataMatrix format
preg_match('/^01(\d{14})21(.{1,20})(.*)$/u', $code, $matches);
return [
'gtin' => $matches[1] ?? null,
'serial' => $matches[2] ?? null,
'crypto' => $matches[3] ?? null,
];
}
The crypto tail contains unreadable group separator characters (GS, ASCII 29). When storing in MySQL make sure the column is utf8mb4 and data type allows such characters — use VARBINARY(200) or VARCHAR(200) with utf8mb4_bin collation.
Generating and Printing Labels
Sometimes you need to generate Data Matrix image for printing labels. PHP library tecnickcom/tcpdf can render Data Matrix. Via Composer:
composer require tecnickcom/tcpdf
Image generation:
$pdf = new \TCPDF();
$pdf->write2DBarcode(
$markingCode,
'DATAMATRIX',
$x, $y, $width, $height,
['border' => false, 'padding' => 1]
);
In Bitrix integrate into the admin section: on the order view page add "Print Labels" button that generates PDF with codes for all marked products in the order. PDF generation is done by AJAX handler in /local/ajax/print_labels.php.
Code Scanning at Receiving
If products are received at the warehouse and Data Matrix needs to be scanned when receiving in Bitrix — create an administrative interface with a code input field (focus on field, scanner sends code and Enter). After entering the code:
- Parse the code, extract GTIN and serial number
- Find the product in catalog by GTIN (property
GTINinb_iblock_element_prop_s*) - Create entry in
b_local_marking_codewith statusreceived - Optionally — send receiving confirmation to GIS MT
For fast work with large number of codes — batch record via INSERT INTO ... VALUES (...), (...), (...) or via ORM D7 addMulti().
Checking Code at Sale
Before checkout or when preparing an order — check code status. Code must be in status received (in stock) and must not already be sold or canceled.
When processing order for assembly — warehouse worker scans marking codes of products in the order. If code matches the expected product and status is correct — position is marked as assembled.
Upon shipment — all codes from the order are transferred to sold status and put in queue for sending notification to GIS MT.
Returns and Code Re-activation
On product return, the marking code must be "returned to circulation". GIS MT has a return operation — code status changes from sold to active. In Bitrix when processing return (event OnSaleOrderReturn or manual processing by manager) transfer code to returned status and send return notification to GIS MT.







