commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
LineItemDraftModel.php
1<?php
2
3declare(strict_types=1);
10
23use DateTimeImmutable;
24use stdClass;
25
29final class LineItemDraftModel extends JsonObjectModel implements LineItemDraft
30{
35 protected $key;
36
41 protected $productId;
42
47 protected $variantId;
48
53 protected $sku;
54
59 protected $quantity;
60
65 protected $addedAt;
66
72
77 protected $supplyChannel;
78
83 protected $externalPrice;
84
90
96
102
107 protected $inventoryMode;
108
114
119 protected $custom;
120
126
127
131 public function __construct(
132 ?string $key = null,
133 ?string $productId = null,
134 ?int $variantId = null,
135 ?string $sku = null,
136 ?int $quantity = null,
137 ?DateTimeImmutable $addedAt = null,
140 ?Money $externalPrice = null,
144 ?string $inventoryMode = null,
148 ) {
149 $this->key = $key;
150 $this->productId = $productId;
151 $this->variantId = $variantId;
152 $this->sku = $sku;
153 $this->quantity = $quantity;
154 $this->addedAt = $addedAt;
155 $this->distributionChannel = $distributionChannel;
156 $this->supplyChannel = $supplyChannel;
157 $this->externalPrice = $externalPrice;
158 $this->externalTotalPrice = $externalTotalPrice;
159 $this->externalTaxRate = $externalTaxRate;
160 $this->perMethodExternalTaxRate = $perMethodExternalTaxRate;
161 $this->inventoryMode = $inventoryMode;
162 $this->shippingDetails = $shippingDetails;
163 $this->custom = $custom;
164 $this->recurrenceInfo = $recurrenceInfo;
165 }
166
173 public function getKey()
174 {
175 if (is_null($this->key)) {
177 $data = $this->raw(self::FIELD_KEY);
178 if (is_null($data)) {
179 return null;
180 }
181 $this->key = (string) $data;
182 }
183
184 return $this->key;
185 }
186
193 public function getProductId()
194 {
195 if (is_null($this->productId)) {
197 $data = $this->raw(self::FIELD_PRODUCT_ID);
198 if (is_null($data)) {
199 return null;
200 }
201 $this->productId = (string) $data;
202 }
203
204 return $this->productId;
205 }
206
214 public function getVariantId()
215 {
216 if (is_null($this->variantId)) {
218 $data = $this->raw(self::FIELD_VARIANT_ID);
219 if (is_null($data)) {
220 return null;
221 }
222 $this->variantId = (int) $data;
223 }
224
225 return $this->variantId;
226 }
227
234 public function getSku()
235 {
236 if (is_null($this->sku)) {
238 $data = $this->raw(self::FIELD_SKU);
239 if (is_null($data)) {
240 return null;
241 }
242 $this->sku = (string) $data;
243 }
244
245 return $this->sku;
246 }
247
254 public function getQuantity()
255 {
256 if (is_null($this->quantity)) {
258 $data = $this->raw(self::FIELD_QUANTITY);
259 if (is_null($data)) {
260 return null;
261 }
262 $this->quantity = (int) $data;
263 }
264
265 return $this->quantity;
266 }
267
276 public function getAddedAt()
277 {
278 if (is_null($this->addedAt)) {
280 $data = $this->raw(self::FIELD_ADDED_AT);
281 if (is_null($data)) {
282 return null;
283 }
284 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
285 if (false === $data) {
286 return null;
287 }
288 $this->addedAt = $data;
289 }
290
291 return $this->addedAt;
292 }
293
303 public function getDistributionChannel()
304 {
305 if (is_null($this->distributionChannel)) {
307 $data = $this->raw(self::FIELD_DISTRIBUTION_CHANNEL);
308 if (is_null($data)) {
309 return null;
310 }
311
312 $this->distributionChannel = ChannelResourceIdentifierModel::of($data);
313 }
314
316 }
317
325 public function getSupplyChannel()
326 {
327 if (is_null($this->supplyChannel)) {
329 $data = $this->raw(self::FIELD_SUPPLY_CHANNEL);
330 if (is_null($data)) {
331 return null;
332 }
333
334 $this->supplyChannel = ChannelResourceIdentifierModel::of($data);
335 }
336
338 }
339
347 public function getExternalPrice()
348 {
349 if (is_null($this->externalPrice)) {
351 $data = $this->raw(self::FIELD_EXTERNAL_PRICE);
352 if (is_null($data)) {
353 return null;
354 }
355
356 $this->externalPrice = MoneyModel::of($data);
357 }
358
360 }
361
368 public function getExternalTotalPrice()
369 {
370 if (is_null($this->externalTotalPrice)) {
372 $data = $this->raw(self::FIELD_EXTERNAL_TOTAL_PRICE);
373 if (is_null($data)) {
374 return null;
375 }
376
377 $this->externalTotalPrice = ExternalLineItemTotalPriceModel::of($data);
378 }
379
381 }
382
389 public function getExternalTaxRate()
390 {
391 if (is_null($this->externalTaxRate)) {
393 $data = $this->raw(self::FIELD_EXTERNAL_TAX_RATE);
394 if (is_null($data)) {
395 return null;
396 }
397
398 $this->externalTaxRate = ExternalTaxRateDraftModel::of($data);
399 }
400
402 }
403
411 {
412 if (is_null($this->perMethodExternalTaxRate)) {
414 $data = $this->raw(self::FIELD_PER_METHOD_EXTERNAL_TAX_RATE);
415 if (is_null($data)) {
416 return null;
417 }
418 $this->perMethodExternalTaxRate = MethodExternalTaxRateDraftCollection::fromArray($data);
419 }
420
422 }
423
431 public function getInventoryMode()
432 {
433 if (is_null($this->inventoryMode)) {
435 $data = $this->raw(self::FIELD_INVENTORY_MODE);
436 if (is_null($data)) {
437 return null;
438 }
439 $this->inventoryMode = (string) $data;
440 }
441
443 }
444
451 public function getShippingDetails()
452 {
453 if (is_null($this->shippingDetails)) {
455 $data = $this->raw(self::FIELD_SHIPPING_DETAILS);
456 if (is_null($data)) {
457 return null;
458 }
459
460 $this->shippingDetails = ItemShippingDetailsDraftModel::of($data);
461 }
462
464 }
465
472 public function getCustom()
473 {
474 if (is_null($this->custom)) {
476 $data = $this->raw(self::FIELD_CUSTOM);
477 if (is_null($data)) {
478 return null;
479 }
480
481 $this->custom = CustomFieldsDraftModel::of($data);
482 }
483
484 return $this->custom;
485 }
486
493 public function getRecurrenceInfo()
494 {
495 if (is_null($this->recurrenceInfo)) {
497 $data = $this->raw(self::FIELD_RECURRENCE_INFO);
498 if (is_null($data)) {
499 return null;
500 }
501
502 $this->recurrenceInfo = LineItemRecurrenceInfoDraftModel::of($data);
503 }
504
506 }
507
508
512 public function setKey(?string $key): void
513 {
514 $this->key = $key;
515 }
516
520 public function setProductId(?string $productId): void
521 {
522 $this->productId = $productId;
523 }
524
528 public function setVariantId(?int $variantId): void
529 {
530 $this->variantId = $variantId;
531 }
532
536 public function setSku(?string $sku): void
537 {
538 $this->sku = $sku;
539 }
540
544 public function setQuantity(?int $quantity): void
545 {
546 $this->quantity = $quantity;
547 }
548
552 public function setAddedAt(?DateTimeImmutable $addedAt): void
553 {
554 $this->addedAt = $addedAt;
555 }
556
561 {
562 $this->distributionChannel = $distributionChannel;
563 }
564
569 {
570 $this->supplyChannel = $supplyChannel;
571 }
572
576 public function setExternalPrice(?Money $externalPrice): void
577 {
578 $this->externalPrice = $externalPrice;
579 }
580
585 {
586 $this->externalTotalPrice = $externalTotalPrice;
587 }
588
593 {
594 $this->externalTaxRate = $externalTaxRate;
595 }
596
601 {
602 $this->perMethodExternalTaxRate = $perMethodExternalTaxRate;
603 }
604
608 public function setInventoryMode(?string $inventoryMode): void
609 {
610 $this->inventoryMode = $inventoryMode;
611 }
612
617 {
618 $this->shippingDetails = $shippingDetails;
619 }
620
624 public function setCustom(?CustomFieldsDraft $custom): void
625 {
626 $this->custom = $custom;
627 }
628
633 {
634 $this->recurrenceInfo = $recurrenceInfo;
635 }
636
637
638 #[\ReturnTypeWillChange]
639 public function jsonSerialize()
640 {
641 $data = $this->toArray();
642 if (isset($data[LineItemDraft::FIELD_ADDED_AT]) && $data[LineItemDraft::FIELD_ADDED_AT] instanceof \DateTimeImmutable) {
643 $data[LineItemDraft::FIELD_ADDED_AT] = $data[LineItemDraft::FIELD_ADDED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
644 }
645 return (object) $data;
646 }
647}
setRecurrenceInfo(?LineItemRecurrenceInfoDraft $recurrenceInfo)
__construct(?string $key=null, ?string $productId=null, ?int $variantId=null, ?string $sku=null, ?int $quantity=null, ?DateTimeImmutable $addedAt=null, ?ChannelResourceIdentifier $distributionChannel=null, ?ChannelResourceIdentifier $supplyChannel=null, ?Money $externalPrice=null, ?ExternalLineItemTotalPrice $externalTotalPrice=null, ?ExternalTaxRateDraft $externalTaxRate=null, ?MethodExternalTaxRateDraftCollection $perMethodExternalTaxRate=null, ?string $inventoryMode=null, ?ItemShippingDetailsDraft $shippingDetails=null, ?CustomFieldsDraft $custom=null, ?LineItemRecurrenceInfoDraft $recurrenceInfo=null)
setDistributionChannel(?ChannelResourceIdentifier $distributionChannel)
setExternalTaxRate(?ExternalTaxRateDraft $externalTaxRate)
setExternalTotalPrice(?ExternalLineItemTotalPrice $externalTotalPrice)
setPerMethodExternalTaxRate(?MethodExternalTaxRateDraftCollection $perMethodExternalTaxRate)
setShippingDetails(?ItemShippingDetailsDraft $shippingDetails)
setSupplyChannel(?ChannelResourceIdentifier $supplyChannel)
static fromArray(array $data)