Skip to content
Encodes and decodes GTIN numbers (EAN-8 and EAN-13)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

GS1 parser and generator for PHP

Encodes and decodes GTIN numbers (EAN-8 and EAN-13) with support for products having variable weight and price.


You can install this package via Composer:

composer require kekos/gs1



Each member country of GS1 have their own specification for products with variable weight and price, magazines and coupons. This is handled by this library by defining encoding rules in "locales".

Currently only the Sweden locale is implemented.

Generate GTIN

Start by creating an entity:

$entity = new \Gs1\Entity\WeightProduct($sku, $weight);
$entity = new \Gs1\Entity\PriceProduct($sku, $price);
$entity = new \Gs1\Entity\Publication($sku, $price);
$entity = new \Gs1\Entity\Coupon($id, $discount);

Use GtinFactory class by specifying which locale to use:

$code = \Gs1\GtinFactory::get('Sweden', $entity);
echo $code;

Parse GTIN

Create a GTIN entity:

$gtin = new \Gs1\Gtin\Gtin13($code);
$gtin = new \Gs1\Gtin\Gtin8($code);

Use EntityFactory class by specifying which locale to use:

$entity = \Gs1\EntityFactory::get('Sweden', $gtin);
if ($entity instanceof \Gs1\Entity\WeightProduct) {
  echo 'Weight: ' . $entity->getWeight();

Product entity

$product = new \Gs1\Entity\Product($sku, $company_prefix);

Weight product entity

$product = new \Gs1\Entity\WeightProduct($sku, $weight);

Price product entity

$product = new \Gs1\Entity\PriceProduct($sku, $price);

Coupon entity

$coupon = new \Gs1\Entity\Coupon($id, $value);

Publication entity

$publication = new \Gs1\Entity\Publication($sku, $price);

GTIN-13 entity (EAN-13) and GTIN-8 entity (EAN-8)

When setting the code you don't have to specify the checksum (digit 8 or 13). The Gtin classes will add the checksum automatically if needed.

$gtin = new \Gs1\Gtin\Gtin8($code);
// ...or
$gtin = new \Gs1\Gtin\Gtin13($code);

$gtin->isValid(); // true or false
$gtin->__toString(); // magic method

Bugs and improvements

Report bugs in GitHub issues or feel free to make a pull request :-)



You can’t perform that action at this time.