OpenXE/classes/Modules/AmazonVendorDF/Data/Container.php

76 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2021-05-21 08:49:41 +02:00
<?php
namespace Xentral\Modules\AmazonVendorDF\Data;
class Container
{
/** @var string */
private $containerType;
/** @var string */
private $containerIdentifier;
/** @var string */
private $length;
/** @var string */
private $width;
/** @var string */
private $height;
/** @var string */
private $unitOfMeasure;
/** @var array */
private $items = [];
public function __construct(string $containerIdentifier, string $containerType = 'carton')
{
$this->containerIdentifier = $containerIdentifier;
$this->containerType = $containerType;
}
public function setDimensions(string $length, string $width, string $height, string $unitOfMeasure = 'CM')
{
$this->length = $length;
$this->width = $width;
$this->height = $height;
$this->unitOfMeasure = $unitOfMeasure;
}
public function addItem(
string $itemSequenceNumber,
string $buyerProductIdentifier,
string $vendorProductIdentifier,
Quantity $packedQuantity
) {
$quantity = $packedQuantity->toArray();
unset($quantity['unitSize']);
$this->items[] = [
'itemSequenceNumber' => (int)$itemSequenceNumber,
'buyerProductIdentifier' => $buyerProductIdentifier,
'vendorProductIdentifier' => $vendorProductIdentifier,
'packedQuantity' => $quantity,
];
}
public function getItems(): array
{
return $this->items;
}
public function toArray()
{
return [
'containerType' => $this->containerType,
'containerIdentifier' => $this->containerIdentifier,
'dimensions' => [
'length' => $this->length,
'width' => $this->width,
'height' => $this->height,
'unitOfMeasure' => $this->unitOfMeasure,
],
'weight' => [
'unitOfMeasure' => 'KG',
'value' => '1',
],
'packedItems' => $this->items,
];
}
}