承接 kekos/gs1 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kekos/gs1

最新稳定版本:v1.0.3

Composer 安装命令:

composer require kekos/gs1

包简介

GS1 parser and generator for PHP

README 文档

README

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

Install

You can install this package via Composer:

composer require kekos/gs1

Documentation

Locales

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);
$product->getSku();
$product->setSku($sku);
$product->getCompanyPrefix();
$product->setCompanyPrefix($company_prefix);

Weight product entity

$product = new \Gs1\Entity\WeightProduct($sku, $weight);
$product->getSku();
$product->setSku($sku);
$product->getWeight();
$product->setWeight($weight);

Price product entity

$product = new \Gs1\Entity\PriceProduct($sku, $price);
$product->getSku();
$product->setSku($sku);
$product->getPrice();
$product->setPrice($price);

Coupon entity

$coupon = new \Gs1\Entity\Coupon($id, $value);
$coupon->getId();
$coupon->setId($id);
$coupon->getValue();
$coupon->setValue($value);

Publication entity

$publication = new \Gs1\Entity\Publication($sku, $price);
$publication->getSku();
$publication->setSku($sku);
$publication->getPrice();
$publication->setPrice($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->getCode();
$gtin->setCode($code);
$gtin->isValid(); // true or false
$gtin->getChecksum();
$gtin->__toString(); // magic method

Bugs and improvements

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

License

MIT

统计信息

  • 总下载量: 5.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-22