baltyre/b2b-client

本包最新版本(v1.1.0)无可用许可信息。

v1.1.0 2024-03-13 10:51 UTC

This package is auto-updated.

Last update: 2024-09-13 11:45:43 UTC


README

介绍

本包提供从 Baltyre B2B API 加载数据的服务。它将原始 JSON 数据映射到漂亮的 DTO(数据传输对象),这对于在 IDE 中提示属性来说很方便。

安装

推荐通过 Composer 进行安装

composer require baltyre/b2b-client

需要 PHP 版本 8.0,并支持 PHP 8.0 到 8.2。

配置

您可以手动创建和配置服务

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

使用方法

目录

要获取所有产品,请调用

$collection = $catalog->load();

这将返回一个包含具有以下属性的 ProductCollection

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;
}

为了更好的可读性,数据被分离到值对象中。

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
}

PatternManufacturer 对象可以包含图片,这些图片由 Picture 对象表示。

class Picture
{
    public string $uri;
}

每张图片的默认大小为 600×600px,以 JPG 格式提供。如果您需要不同大小或格式的图片,可以使用内置方法

$resizedPicture      = $picture->withFormat(1000, 1000); 
$resizedPictureInPng = $picture->withFormat(800, 800, Picture::PNG); 

价格表

要加载价格表,请调用

$collection = $pricelist->load();

这将返回一个包含具有以下属性的 PriceListCollection

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
}

库存

要加载库存资源,请调用

$collection = $stock->load();

这将返回一个包含具有以下属性的 StockCollection

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
}