commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CartAddLineItemActionModel.php
1<?php
2
3declare(strict_types=1);
10
23use DateTimeImmutable;
24use stdClass;
25
30{
31 public const DISCRIMINATOR_VALUE = 'addLineItem';
36 protected $action;
37
42 protected $key;
43
48 protected $productId;
49
54 protected $variantId;
55
60 protected $sku;
61
66 protected $quantity;
67
72 protected $addedAt;
73
79
84 protected $supplyChannel;
85
90 protected $externalPrice;
91
97
103
109
114 protected $inventoryMode;
115
121
127
132 protected $custom;
133
134
138 public function __construct(
139 ?string $key = null,
140 ?string $productId = null,
141 ?int $variantId = null,
142 ?string $sku = null,
143 ?int $quantity = null,
144 ?DateTimeImmutable $addedAt = null,
147 ?Money $externalPrice = null,
151 ?string $inventoryMode = null,
155 ?string $action = null
156 ) {
157 $this->key = $key;
158 $this->productId = $productId;
159 $this->variantId = $variantId;
160 $this->sku = $sku;
161 $this->quantity = $quantity;
162 $this->addedAt = $addedAt;
163 $this->distributionChannel = $distributionChannel;
164 $this->supplyChannel = $supplyChannel;
165 $this->externalPrice = $externalPrice;
166 $this->externalTotalPrice = $externalTotalPrice;
167 $this->externalTaxRate = $externalTaxRate;
168 $this->perMethodExternalTaxRate = $perMethodExternalTaxRate;
169 $this->inventoryMode = $inventoryMode;
170 $this->shippingDetails = $shippingDetails;
171 $this->recurrenceInfo = $recurrenceInfo;
172 $this->custom = $custom;
173 $this->action = $action ?? self::DISCRIMINATOR_VALUE;
174 }
175
180 public function getAction()
181 {
182 if (is_null($this->action)) {
184 $data = $this->raw(self::FIELD_ACTION);
185 if (is_null($data)) {
186 return null;
187 }
188 $this->action = (string) $data;
189 }
190
191 return $this->action;
192 }
193
200 public function getKey()
201 {
202 if (is_null($this->key)) {
204 $data = $this->raw(self::FIELD_KEY);
205 if (is_null($data)) {
206 return null;
207 }
208 $this->key = (string) $data;
209 }
210
211 return $this->key;
212 }
213
221 public function getProductId()
222 {
223 if (is_null($this->productId)) {
225 $data = $this->raw(self::FIELD_PRODUCT_ID);
226 if (is_null($data)) {
227 return null;
228 }
229 $this->productId = (string) $data;
230 }
231
232 return $this->productId;
233 }
234
243 public function getVariantId()
244 {
245 if (is_null($this->variantId)) {
247 $data = $this->raw(self::FIELD_VARIANT_ID);
248 if (is_null($data)) {
249 return null;
250 }
251 $this->variantId = (int) $data;
252 }
253
254 return $this->variantId;
255 }
256
264 public function getSku()
265 {
266 if (is_null($this->sku)) {
268 $data = $this->raw(self::FIELD_SKU);
269 if (is_null($data)) {
270 return null;
271 }
272 $this->sku = (string) $data;
273 }
274
275 return $this->sku;
276 }
277
284 public function getQuantity()
285 {
286 if (is_null($this->quantity)) {
288 $data = $this->raw(self::FIELD_QUANTITY);
289 if (is_null($data)) {
290 return null;
291 }
292 $this->quantity = (int) $data;
293 }
294
295 return $this->quantity;
296 }
297
306 public function getAddedAt()
307 {
308 if (is_null($this->addedAt)) {
310 $data = $this->raw(self::FIELD_ADDED_AT);
311 if (is_null($data)) {
312 return null;
313 }
314 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
315 if (false === $data) {
316 return null;
317 }
318 $this->addedAt = $data;
319 }
320
321 return $this->addedAt;
322 }
323
332 public function getDistributionChannel()
333 {
334 if (is_null($this->distributionChannel)) {
336 $data = $this->raw(self::FIELD_DISTRIBUTION_CHANNEL);
337 if (is_null($data)) {
338 return null;
339 }
340
341 $this->distributionChannel = ChannelResourceIdentifierModel::of($data);
342 }
343
345 }
346
354 public function getSupplyChannel()
355 {
356 if (is_null($this->supplyChannel)) {
358 $data = $this->raw(self::FIELD_SUPPLY_CHANNEL);
359 if (is_null($data)) {
360 return null;
361 }
362
363 $this->supplyChannel = ChannelResourceIdentifierModel::of($data);
364 }
365
367 }
368
376 public function getExternalPrice()
377 {
378 if (is_null($this->externalPrice)) {
380 $data = $this->raw(self::FIELD_EXTERNAL_PRICE);
381 if (is_null($data)) {
382 return null;
383 }
384
385 $this->externalPrice = MoneyModel::of($data);
386 }
387
389 }
390
397 public function getExternalTotalPrice()
398 {
399 if (is_null($this->externalTotalPrice)) {
401 $data = $this->raw(self::FIELD_EXTERNAL_TOTAL_PRICE);
402 if (is_null($data)) {
403 return null;
404 }
405
406 $this->externalTotalPrice = ExternalLineItemTotalPriceModel::of($data);
407 }
408
410 }
411
418 public function getExternalTaxRate()
419 {
420 if (is_null($this->externalTaxRate)) {
422 $data = $this->raw(self::FIELD_EXTERNAL_TAX_RATE);
423 if (is_null($data)) {
424 return null;
425 }
426
427 $this->externalTaxRate = ExternalTaxRateDraftModel::of($data);
428 }
429
431 }
432
440 {
441 if (is_null($this->perMethodExternalTaxRate)) {
443 $data = $this->raw(self::FIELD_PER_METHOD_EXTERNAL_TAX_RATE);
444 if (is_null($data)) {
445 return null;
446 }
447 $this->perMethodExternalTaxRate = MethodExternalTaxRateDraftCollection::fromArray($data);
448 }
449
451 }
452
460 public function getInventoryMode()
461 {
462 if (is_null($this->inventoryMode)) {
464 $data = $this->raw(self::FIELD_INVENTORY_MODE);
465 if (is_null($data)) {
466 return null;
467 }
468 $this->inventoryMode = (string) $data;
469 }
470
472 }
473
480 public function getShippingDetails()
481 {
482 if (is_null($this->shippingDetails)) {
484 $data = $this->raw(self::FIELD_SHIPPING_DETAILS);
485 if (is_null($data)) {
486 return null;
487 }
488
489 $this->shippingDetails = ItemShippingDetailsDraftModel::of($data);
490 }
491
493 }
494
501 public function getRecurrenceInfo()
502 {
503 if (is_null($this->recurrenceInfo)) {
505 $data = $this->raw(self::FIELD_RECURRENCE_INFO);
506 if (is_null($data)) {
507 return null;
508 }
509
510 $this->recurrenceInfo = LineItemRecurrenceInfoDraftModel::of($data);
511 }
512
514 }
515
522 public function getCustom()
523 {
524 if (is_null($this->custom)) {
526 $data = $this->raw(self::FIELD_CUSTOM);
527 if (is_null($data)) {
528 return null;
529 }
530
531 $this->custom = CustomFieldsDraftModel::of($data);
532 }
533
534 return $this->custom;
535 }
536
537
541 public function setKey(?string $key): void
542 {
543 $this->key = $key;
544 }
545
549 public function setProductId(?string $productId): void
550 {
551 $this->productId = $productId;
552 }
553
557 public function setVariantId(?int $variantId): void
558 {
559 $this->variantId = $variantId;
560 }
561
565 public function setSku(?string $sku): void
566 {
567 $this->sku = $sku;
568 }
569
573 public function setQuantity(?int $quantity): void
574 {
575 $this->quantity = $quantity;
576 }
577
581 public function setAddedAt(?DateTimeImmutable $addedAt): void
582 {
583 $this->addedAt = $addedAt;
584 }
585
590 {
591 $this->distributionChannel = $distributionChannel;
592 }
593
598 {
599 $this->supplyChannel = $supplyChannel;
600 }
601
605 public function setExternalPrice(?Money $externalPrice): void
606 {
607 $this->externalPrice = $externalPrice;
608 }
609
614 {
615 $this->externalTotalPrice = $externalTotalPrice;
616 }
617
622 {
623 $this->externalTaxRate = $externalTaxRate;
624 }
625
630 {
631 $this->perMethodExternalTaxRate = $perMethodExternalTaxRate;
632 }
633
637 public function setInventoryMode(?string $inventoryMode): void
638 {
639 $this->inventoryMode = $inventoryMode;
640 }
641
646 {
647 $this->shippingDetails = $shippingDetails;
648 }
649
654 {
655 $this->recurrenceInfo = $recurrenceInfo;
656 }
657
661 public function setCustom(?CustomFieldsDraft $custom): void
662 {
663 $this->custom = $custom;
664 }
665
666
667 #[\ReturnTypeWillChange]
668 public function jsonSerialize()
669 {
670 $data = $this->toArray();
671 if (isset($data[CartAddLineItemAction::FIELD_ADDED_AT]) && $data[CartAddLineItemAction::FIELD_ADDED_AT] instanceof \DateTimeImmutable) {
672 $data[CartAddLineItemAction::FIELD_ADDED_AT] = $data[CartAddLineItemAction::FIELD_ADDED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
673 }
674 return (object) $data;
675 }
676}
setRecurrenceInfo(?LineItemRecurrenceInfoDraft $recurrenceInfo)
setShippingDetails(?ItemShippingDetailsDraft $shippingDetails)
setPerMethodExternalTaxRate(?MethodExternalTaxRateDraftCollection $perMethodExternalTaxRate)
__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, ?LineItemRecurrenceInfoDraft $recurrenceInfo=null, ?CustomFieldsDraft $custom=null, ?string $action=null)
setDistributionChannel(?ChannelResourceIdentifier $distributionChannel)
setExternalTotalPrice(?ExternalLineItemTotalPrice $externalTotalPrice)
static fromArray(array $data)