2022-10-21 10:46:09 +02:00
|
|
|
<?php
|
|
|
|
|
2023-02-28 13:36:25 +01:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2022 Andreas Palm
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-10-21 10:46:09 +02:00
|
|
|
namespace Xentral\Carrier\SendCloud\Data;
|
|
|
|
|
|
|
|
class ParcelItem
|
|
|
|
{
|
|
|
|
public string $HsCode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int weight in grams
|
|
|
|
*/
|
|
|
|
public int $Weight;
|
|
|
|
public int $Quantity;
|
|
|
|
public string $Description;
|
|
|
|
public string $OriginCountry;
|
|
|
|
public float $Price;
|
2022-10-29 21:38:28 +02:00
|
|
|
public ?string $Sku = null;
|
|
|
|
public ?string $ProductId = null;
|
2022-10-21 10:46:09 +02:00
|
|
|
|
|
|
|
public function toApiRequest(): array {
|
|
|
|
return [
|
|
|
|
'hs_code' => $this->HsCode,
|
|
|
|
'weight' => number_format($this->Weight / 1000, 3, '.', null),
|
|
|
|
'quantity' => $this->Quantity,
|
|
|
|
'description' => $this->Description,
|
2022-10-29 21:38:28 +02:00
|
|
|
'value' => $this->Price,
|
2022-10-21 10:46:09 +02:00
|
|
|
'origin_country' => $this->OriginCountry,
|
2022-10-29 21:38:28 +02:00
|
|
|
'sku' => $this->Sku ?? '',
|
|
|
|
'product_id' => $this->ProductId ?? '',
|
2022-10-21 10:46:09 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function fromApiResponse(object $data): ParcelItem
|
|
|
|
{
|
|
|
|
$obj = new ParcelItem();
|
|
|
|
$obj->HsCode = $data->hs_code;
|
|
|
|
$obj->Weight = intval(floatval($data->weight)*1000);
|
|
|
|
$obj->Quantity = $data->quantity;
|
|
|
|
$obj->Description = $data->description;
|
2022-10-29 21:38:28 +02:00
|
|
|
$obj->Price = $data->value;
|
2022-10-21 10:46:09 +02:00
|
|
|
$obj->OriginCountry = $data->origin_country;
|
|
|
|
$obj->Sku = $data->sku;
|
|
|
|
$obj->ProductId = $data->product_id;
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
}
|