commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
InventoryImportModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
21 use DateTimeImmutable;
22 use stdClass;
23 
28 {
33  protected $key;
34 
39  protected $sku;
40 
45  protected $quantityOnStock;
46 
51  protected $restockableInDays;
52 
57  protected $expectedDelivery;
58 
63  protected $supplyChannel;
64 
69  protected $custom;
70 
71 
75  public function __construct(
76  ?string $key = null,
77  ?string $sku = null,
78  ?int $quantityOnStock = null,
79  ?int $restockableInDays = null,
80  ?DateTimeImmutable $expectedDelivery = null,
82  ?Custom $custom = null
83  ) {
84  $this->key = $key;
85  $this->sku = $sku;
86  $this->quantityOnStock = $quantityOnStock;
87  $this->restockableInDays = $restockableInDays;
88  $this->expectedDelivery = $expectedDelivery;
89  $this->supplyChannel = $supplyChannel;
90  $this->custom = $custom;
91  }
92 
99  public function getKey()
100  {
101  if (is_null($this->key)) {
103  $data = $this->raw(self::FIELD_KEY);
104  if (is_null($data)) {
105  return null;
106  }
107  $this->key = (string) $data;
108  }
109 
110  return $this->key;
111  }
112 
119  public function getSku()
120  {
121  if (is_null($this->sku)) {
123  $data = $this->raw(self::FIELD_SKU);
124  if (is_null($data)) {
125  return null;
126  }
127  $this->sku = (string) $data;
128  }
129 
130  return $this->sku;
131  }
132 
139  public function getQuantityOnStock()
140  {
141  if (is_null($this->quantityOnStock)) {
143  $data = $this->raw(self::FIELD_QUANTITY_ON_STOCK);
144  if (is_null($data)) {
145  return null;
146  }
147  $this->quantityOnStock = (int) $data;
148  }
149 
150  return $this->quantityOnStock;
151  }
152 
159  public function getRestockableInDays()
160  {
161  if (is_null($this->restockableInDays)) {
163  $data = $this->raw(self::FIELD_RESTOCKABLE_IN_DAYS);
164  if (is_null($data)) {
165  return null;
166  }
167  $this->restockableInDays = (int) $data;
168  }
169 
171  }
172 
179  public function getExpectedDelivery()
180  {
181  if (is_null($this->expectedDelivery)) {
183  $data = $this->raw(self::FIELD_EXPECTED_DELIVERY);
184  if (is_null($data)) {
185  return null;
186  }
187  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
188  if (false === $data) {
189  return null;
190  }
191  $this->expectedDelivery = $data;
192  }
193 
195  }
196 
203  public function getSupplyChannel()
204  {
205  if (is_null($this->supplyChannel)) {
207  $data = $this->raw(self::FIELD_SUPPLY_CHANNEL);
208  if (is_null($data)) {
209  return null;
210  }
211 
212  $this->supplyChannel = ChannelKeyReferenceModel::of($data);
213  }
214 
215  return $this->supplyChannel;
216  }
217 
224  public function getCustom()
225  {
226  if (is_null($this->custom)) {
228  $data = $this->raw(self::FIELD_CUSTOM);
229  if (is_null($data)) {
230  return null;
231  }
232 
233  $this->custom = CustomModel::of($data);
234  }
235 
236  return $this->custom;
237  }
238 
239 
243  public function setKey(?string $key): void
244  {
245  $this->key = $key;
246  }
247 
251  public function setSku(?string $sku): void
252  {
253  $this->sku = $sku;
254  }
255 
259  public function setQuantityOnStock(?int $quantityOnStock): void
260  {
261  $this->quantityOnStock = $quantityOnStock;
262  }
263 
267  public function setRestockableInDays(?int $restockableInDays): void
268  {
269  $this->restockableInDays = $restockableInDays;
270  }
271 
275  public function setExpectedDelivery(?DateTimeImmutable $expectedDelivery): void
276  {
277  $this->expectedDelivery = $expectedDelivery;
278  }
279 
284  {
285  $this->supplyChannel = $supplyChannel;
286  }
287 
291  public function setCustom(?Custom $custom): void
292  {
293  $this->custom = $custom;
294  }
295 
296 
297  #[\ReturnTypeWillChange]
298  public function jsonSerialize()
299  {
300  $data = $this->toArray();
301  if (isset($data[InventoryImport::FIELD_EXPECTED_DELIVERY]) && $data[InventoryImport::FIELD_EXPECTED_DELIVERY] instanceof \DateTimeImmutable) {
302  $data[InventoryImport::FIELD_EXPECTED_DELIVERY] = $data[InventoryImport::FIELD_EXPECTED_DELIVERY]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
303  }
304  return (object) $data;
305  }
306 }
__construct(?string $key=null, ?string $sku=null, ?int $quantityOnStock=null, ?int $restockableInDays=null, ?DateTimeImmutable $expectedDelivery=null, ?ChannelKeyReference $supplyChannel=null, ?Custom $custom=null)