PHP code example of kekos / gs1

1. Go to this page and download the library: Download kekos/gs1 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kekos / gs1 example snippets


$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);

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

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

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

$product = new \Gs1\Entity\Product($sku, $company_prefix);
$product->getSku();
$product->setSku($sku);
$product->getCompanyPrefix();
$product->setCompanyPrefix($company_prefix);

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

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

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

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

$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