PHP code example of silvershop-suite / product-identity

1. Go to this page and download the library: Download silvershop-suite/product-identity 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/ */

    

silvershop-suite / product-identity example snippets


use SilverShop\ProductIdentity\GtinValidator;

GtinValidator::isValid('4006381333931'); // true  (valid EAN-13)
GtinValidator::isValid('4006381333930'); // false (bad check digit)
GtinValidator::normalise('40 06381-333931'); // "4006381333931"

$buyable->getResolvedGtin();  // variation's own GTIN, else the product's; a product returns its own
$buyable->getResolvedMpn();   // same fallback for MPN
$buyable->getHasIdentifier(); // true when a GTIN or MPN is present (own or inherited)

$gtin = $buyable->hasMethod('getResolvedGtin') ? $buyable->getResolvedGtin() : '';