commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
DeliveryModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
17 use DateTimeImmutable;
18 use stdClass;
19 
23 final class DeliveryModel extends JsonObjectModel implements Delivery
24 {
29  protected $id;
30 
35  protected $createdAt;
36 
41  protected $items;
42 
47  protected $parcels;
48 
53  protected $address;
54 
55 
59  public function __construct(
60  ?string $id = null,
61  ?DateTimeImmutable $createdAt = null,
63  ?ParcelCollection $parcels = null,
64  ?Address $address = null
65  ) {
66  $this->id = $id;
67  $this->createdAt = $createdAt;
68  $this->items = $items;
69  $this->parcels = $parcels;
70  $this->address = $address;
71  }
72 
77  public function getId()
78  {
79  if (is_null($this->id)) {
81  $data = $this->raw(self::FIELD_ID);
82  if (is_null($data)) {
83  return null;
84  }
85  $this->id = (string) $data;
86  }
87 
88  return $this->id;
89  }
90 
95  public function getCreatedAt()
96  {
97  if (is_null($this->createdAt)) {
99  $data = $this->raw(self::FIELD_CREATED_AT);
100  if (is_null($data)) {
101  return null;
102  }
103  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
104  if (false === $data) {
105  return null;
106  }
107  $this->createdAt = $data;
108  }
109 
110  return $this->createdAt;
111  }
112 
117  public function getItems()
118  {
119  if (is_null($this->items)) {
121  $data = $this->raw(self::FIELD_ITEMS);
122  if (is_null($data)) {
123  return null;
124  }
125  $this->items = DeliveryItemCollection::fromArray($data);
126  }
127 
128  return $this->items;
129  }
130 
135  public function getParcels()
136  {
137  if (is_null($this->parcels)) {
139  $data = $this->raw(self::FIELD_PARCELS);
140  if (is_null($data)) {
141  return null;
142  }
143  $this->parcels = ParcelCollection::fromArray($data);
144  }
145 
146  return $this->parcels;
147  }
148 
153  public function getAddress()
154  {
155  if (is_null($this->address)) {
157  $data = $this->raw(self::FIELD_ADDRESS);
158  if (is_null($data)) {
159  return null;
160  }
161 
162  $this->address = AddressModel::of($data);
163  }
164 
165  return $this->address;
166  }
167 
168 
172  public function setId(?string $id): void
173  {
174  $this->id = $id;
175  }
176 
180  public function setCreatedAt(?DateTimeImmutable $createdAt): void
181  {
182  $this->createdAt = $createdAt;
183  }
184 
188  public function setItems(?DeliveryItemCollection $items): void
189  {
190  $this->items = $items;
191  }
192 
196  public function setParcels(?ParcelCollection $parcels): void
197  {
198  $this->parcels = $parcels;
199  }
200 
204  public function setAddress(?Address $address): void
205  {
206  $this->address = $address;
207  }
208 
209 
210  #[\ReturnTypeWillChange]
211  public function jsonSerialize()
212  {
213  $data = $this->toArray();
214  if (isset($data[Delivery::FIELD_CREATED_AT]) && $data[Delivery::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
215  $data[Delivery::FIELD_CREATED_AT] = $data[Delivery::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
216  }
217  return (object) $data;
218  }
219 }
setItems(?DeliveryItemCollection $items)
__construct(?string $id=null, ?DateTimeImmutable $createdAt=null, ?DeliveryItemCollection $items=null, ?ParcelCollection $parcels=null, ?Address $address=null)
setCreatedAt(?DateTimeImmutable $createdAt)