PHP code example of ribal / onix

1. Go to this page and download the library: Download ribal/onix 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/ */

    

ribal / onix example snippets



$parser = new \Ribal\Onix\Parser();

/** @var Ribal\Onix\Message\Message; */
$message = $parser->parseString(
    file_get_contents('sample.xml')
);

/** @var Ribal\Onix\Product\Product[] */
$products = $message->getProducts();

// Either get the Code object and read it's code and/or value
$type = $product->getNotificationType();
$code = $code->getCode();   // "03"
$value = $code->getValue(); // "Notification confirmed on publication"

// or directly get the value as string
$value = (string) $product->getNotificationType();

// Create parser using german code list values
$parser = new \Ribal\Onix\Parser('de');

// get the DescriptiveDetail portion of the product
$descriptiveDetail = $product->getDescriptiveDetail();

foreach ($descriptiveDetail->getMeasures() as $measure) {
	echo sprintf('%s: %s %s',                      // -> "Height: 210 Centimeters"
		(string) $measure->getMeasureType(),       // e.g. "Height"
		$measure->getMeasurement(),                // e.g. "210"
		(string) $measure->getMeasureUnitCode()    // e.g. "Centimeters"
	);
}

/** @var Ribal\Onix\Product\Measure */
$height = $descriptiveDetail->getHeight();
$width = $descriptiveDetail->getWidth();
$thickness = $descriptiveDetail->getThickness();
$weight = $descriptiveDetail->getWeight();

echo sprintf("Height: %s %s", $height->getMeasurement(), $height->getMeasureUnitCode()->getCode());
// --> Height: 210 cm
xml
<ONIXMessage>
    <Product>
        <NotificationType>03</NotificationType>
        [...]
    </Product>
</ONIXMessage>