PHP code example of millancore / alegra

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

    

millancore / alegra example snippets


use Alegra\Alegra;
use Alegra\Support\Country;

$alegra = Alegra::setCredentials([
    'email' => '[email protected]',
    'token' => 'tokenAuthApiAccess',
    'country' => Country::COL
]);


$alegra->setLogger($PSRLogger);



$alegra->addListener($myListener);



use Alegra\Support\Facade\Item;

$product = Item::get(12);


$product = Item::get(12);

$product->id
$product->name
$product->... 

$arrayProduct = $product->toArray();

$jsonProduct = json_encode($product);

foreach($product->price as $price) {
    #Price Entity
}

$product->price->count();

$arrayPriceList = $product->price->toArray(); 

$jsonPriceList = json_encode($product->price); 

use Alegra\Support\Facade\Item;
use Alegra\Exception\AlegraException;

try {
    $product = Item::get(12);
} catch (AlegraException $exception) {
    #....
}