Updated ShippingOption

This commit is contained in:
netkas 2024-10-04 15:18:43 -04:00
parent 147e4141b9
commit 7f7f353ed5

View file

@ -7,20 +7,12 @@
class ShippingOption implements ObjectTypeInterface class ShippingOption implements ObjectTypeInterface
{ {
/** private string $id;
* @var string private string $title;
*/
private $id;
/**
* @var string
*/
private $title;
/** /**
* @var LabeledPrice[] * @var LabeledPrice[]
*/ */
private $prices; private array $prices;
/** /**
* Shipping option identifier * Shipping option identifier
@ -62,26 +54,24 @@
return [ return [
'id' => $this->id, 'id' => $this->id,
'title' => $this->title, 'title' => $this->title,
'prices' => array_map(function (LabeledPrice $price) { 'prices' => array_map(fn(LabeledPrice $item) => $item->toArray(), $this->prices)
return $price->toArray();
}, $this->prices)
]; ];
} }
/** /**
* Constructs object from an array representation * @inheritDoc
*
* @param array $data
* @return ShippingOption
*/ */
public static function fromArray(array $data): self public static function fromArray(?array $data): ?ShippingOption
{ {
if($data === null)
{
return null;
}
$object = new self(); $object = new self();
$object->id = $data['id']; $object->id = $data['id'];
$object->title = $data['title']; $object->title = $data['title'];
$object->prices = array_map(function (array $price) { $object->prices = array_map(fn($item) => LabeledPrice::fromArray($item), $data['prices']);
return LabeledPrice::fromArray($price);
}, $data['prices']);
return $object; return $object;
} }