This package offers services to loading data from Baltyre B2B API. It maps raw JSON data to pretty DTO's (data transfer objects), that is nice e.g. for hinting properties in your IDE.
The recommended way to install is via Composer:
composer require baltyre/b2b-client
It requires PHP version 8.0 and supports PHP up to 8.2.
You can create and configure services manualy:
use Baltyre\B2BClient\ApiConnector;
use Baltyre\B2BClient\CatalogLoader;
use Baltyre\B2BClient\PriceListLoader;
use Baltyre\B2BClient\StockLoader;
$apiKey = "<your-secrect-api-key>";
$baseUrl = "https://b2b.baltyre.com/api";
// for HU customers: $baseUrl = "https://b2b.baltyre.hu/api";
// for AT customers: $baseUrl = "https://b2b.osterreifen.com/api";
$connector = new ApiConnector($baseUrl, $apiKey);
$catalog = new CatalogLoader($connector);
$pricelist = new PriceListLoader($connector);
$stock = new StockLoader($connector);
To get all products just call:
$collection = $catalog->load();
This returns a ProductCollection
that constains ProductData
objects with next properties:
class ProductData
{
public string $code; // product code (PLU if present, otherwise CDB)
public string $cdb; // product CDB code
public ?string $plu; // product PLU code
public string $name; // product name
public ?string $ean; // EAN
public ?string $manufacturer_code; // code from manufacturer
public ?Manufacturer $manufacturer;
public ?Pattern $pattern;
public ?ParameterCollection $parameters; // collection that containst `Parameter` objects
public ?CategoryCollection $categories; // collection that containst `Category` objects
public ?Volume $volume;
public ?Weight $weight;
}
For better readability are data separated to value objects.
class Manufacturer
{
public string $code; // manufacturer internal code
public string $name; // manufacturer public name
public ?Picture $picture;
}
class Pattern
{
public string $name;
public ?string $description;
public ?string $season;
public ?string $purpose;
public ?Picture $picture;
public ?PictureCollection $pictures; // collection that containst `Picture` objects
}
class Parameter
{
public string $code; // parameter internal code
public string $name; // parameter public name
public ?string $value; // parameter value
}
class Category
{
public string $code; // category internal code
public string $name; // category public name
}
Objects of Pattern
and Manufacturer
can contain pictures, which are represented by the Picture
object.
class Picture
{
public string $uri;
}
Default size of each picture is 600×600px and is provided in JPG format. If you need a picture in a different size or format, you can use the built-in method:
$resizedPicture = $picture->withFormat(1000, 1000);
$resizedPictureInPng = $picture->withFormat(800, 800, Picture::PNG);
To load pricelist call:
$collection = $pricelist->load();
This returns a PriceListCollection
that constains ProductPricing
objects with next properties:
class ProductPricing
{
public string $code; // product code (PLU if present, otherwise CDB)
public string $cdb; // product CDB code
public ?string $plu; // product PLU code
public ?PricePolicy $price;
}
class PricePolicy
{
public Price $sale; // end-customer price
public Price $purchase; // your purchase (discounted) price
}
To load stock resources call:
$collection = $stock->load();
This returns a StockCollection
that constains ProductStocks
objects with next properties:
class ProductStocks
{
public string $code; // product code (PLU if present, otherwise CDB)
public string $cdb; // product CDB code
public ?string $plu; // product PLU code
public ?ResourceCollection $stock; // collection that containst `StockResource` objects
}
class StockResource
{
public string $code; // stock code
public string $name; // stock name
public int $days; // approximate delivery time from order confirmation
public int $quantity; // number of pcs in this stock
public bool $moreThanQuantity; // determines if quantity is exact or minimal
}