silvershop-suite / barcodes
Barcode image generation for SilverShop (CMS 6): render EAN-13, Code128 and QR codes to inline SVG or a PNG data-URI, from any code string or — guarded — from a product's GTIN stored by silvershop-suite/product-identity. For packing slips, invoices, shipping labels, PDFs and POS/scanning. Generation
Package info
github.com/silvershop-suite/silvershop-barcodes
Type:silverstripe-vendormodule
pkg:composer/silvershop-suite/barcodes
Requires
- php: ^8.3
- endroid/qr-code: ^5.0
- picqer/php-barcode-generator: ^3.0
- silverstripe/cms: ^6.0
- silverstripe/framework: ^6.0
Requires (Dev)
Suggests
- ext-gd: Enables PNG output (picqer PNG + endroid PngWriter); SVG output needs no extension.
- silvershop-suite/product-identity: Auto-exposes a product's GTIN as a barcode on Product and Variation (the $BarcodeSVG / $Code128SVG / $QrCodeSVG template accessors); without it, barcodes still renders any code string you hand the BarcodeGenerator service.
- silvershop/core: Required by silvershop-suite/product-identity; needed for the Product/Variation template accessors (the generator service itself is standalone).
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-19 19:35:04 UTC
README
Barcode image generation for SilverShop on Silverstripe CMS 6.
Render EAN-13, Code128 and QR codes to inline SVG (the default) or a PNG data-URI — from any
code string, or, guarded, from the GTIN that silvershop-suite/product-identity
stores on your products. For packing slips, invoices, shipping labels, PDFs and POS / scanning.
This module is generation only: it never stores or validates codes — that is silvershop-suite/product-identity's
job. Because of that it is also useful standalone: hand the BarcodeGenerator service any string and get a
barcode back, with or without SilverShop installed.
Requirements
- PHP 8.3+
silverstripe/framework^6.0,silverstripe/cms^6.0picqer/php-barcode-generator^3 (EAN-13 / Code128),endroid/qr-code^5 (QR)ext-gd— only for PNG output; SVG needs no extension
Optional (soft dependency): silvershop-suite/product-identity — auto-exposes a product's GTIN as a barcode on
Product and Variation.
Installation
composer require silvershop-suite/barcodes
Then run dev/build?flush=all.
The service
SilverShop\Barcodes\BarcodeGenerator is a stateless, injectable service:
use SilverShop\Barcodes\BarcodeGenerator; $generator = BarcodeGenerator::singleton(); // render(string $code, ?string $symbology = 'ean13', ?string $format = 'svg', array $opts = []): string $svg = $generator->render('4006381333931', 'ean13'); // inline <svg> markup $code128 = $generator->render('ORDER-2026-000123', 'code128'); // any string $qrSvg = $generator->render('https://shop.example/p/42', 'qr'); // QR as SVG $pngUri = $generator->render('4006381333931', 'ean13', 'png'); // data:image/png;base64,…
Supported symbologies: ean13, code128, qr. Per-call $opts: scale, height (1D); size, margin
(QR); foreground, background (hex colours).
Configuration
SilverShop\Barcodes\BarcodeGenerator: default_symbology: ean13 default_format: svg bar_width_factor: 2 bar_height: 50 qr_size: 220 qr_margin: 10 foreground_color: '#000000' background_color: '#ffffff' # Add more picqer linear symbologies without code: symbologies: ean8: kind: linear type: EAN8 numeric: true lengths: [7, 8]
Errors
render() throws UnsupportedSymbologyException for an unknown symbology token, and BarcodeGenerationException
when a code cannot be drawn as the requested symbology (empty code, a non-numeric or wrong-length EAN-13, an
unknown format, or a failure inside the underlying library). This is a rendering guard, not GS1 validation — it
simply refuses to emit a misleading barcode (e.g. picqer would otherwise silently zero-pad a too-short EAN-13).
Template accessors (with silvershop-suite/product-identity)
When silvershop-suite/product-identity is installed, Product and Variation gain barcode accessors that read the
resolved GTIN (variant → product fallback included) guarded — so nothing breaks when a code or the module is
absent:
<% if $BarcodeSVG %>$BarcodeSVG<% end_if %> <%-- EAN-13 for a 13-digit code, else Code128 --%> $Code128SVG <%-- always Code128 --%> $QrCodeSVG <%-- QR --%> <img src="$BarcodePNG" alt="barcode"> <%-- PNG data-URI --%>
Inline SVG embeds directly into packing-slip / invoice / label templates and PDFs with no controller and no asset file. When the buyable has no code (or product-identity is not installed) every accessor is empty.
The accessor is applied only when silvershop/core is present; the BarcodeGenerator service works regardless.
Licence
BSD-3-Clause.
Credits
Built and maintained by Remy Vaartjes (remy@xd.nl) — part of the SilverShop-Suite.