commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CartDiscountModel.php
1<?php
2
3declare(strict_types=1);
10
29use DateTimeImmutable;
30use stdClass;
31
35final class CartDiscountModel extends JsonObjectModel implements CartDiscount
36{
41 protected $id;
42
47 protected $version;
48
53 protected $createdAt;
54
59 protected $lastModifiedAt;
60
65 protected $lastModifiedBy;
66
71 protected $createdBy;
72
77 protected $name;
78
83 protected $key;
84
89 protected $description;
90
95 protected $value;
96
101 protected $cartPredicate;
102
107 protected $target;
108
113 protected $sortOrder;
114
119 protected $stores;
120
125 protected $isActive;
126
131 protected $validFrom;
132
137 protected $validUntil;
138
144
149 protected $references;
150
155 protected $stackingMode;
156
161 protected $custom;
162
167 protected $discountGroup;
168
169
173 public function __construct(
174 ?string $id = null,
175 ?int $version = null,
176 ?DateTimeImmutable $createdAt = null,
177 ?DateTimeImmutable $lastModifiedAt = null,
179 ?CreatedBy $createdBy = null,
180 ?LocalizedString $name = null,
181 ?string $key = null,
184 ?string $cartPredicate = null,
186 ?string $sortOrder = null,
188 ?bool $isActive = null,
189 ?DateTimeImmutable $validFrom = null,
190 ?DateTimeImmutable $validUntil = null,
191 ?bool $requiresDiscountCode = null,
193 ?string $stackingMode = null,
194 ?CustomFields $custom = null,
196 ) {
197 $this->id = $id;
198 $this->version = $version;
199 $this->createdAt = $createdAt;
200 $this->lastModifiedAt = $lastModifiedAt;
201 $this->lastModifiedBy = $lastModifiedBy;
202 $this->createdBy = $createdBy;
203 $this->name = $name;
204 $this->key = $key;
205 $this->description = $description;
206 $this->value = $value;
207 $this->cartPredicate = $cartPredicate;
208 $this->target = $target;
209 $this->sortOrder = $sortOrder;
210 $this->stores = $stores;
211 $this->isActive = $isActive;
212 $this->validFrom = $validFrom;
213 $this->validUntil = $validUntil;
214 $this->requiresDiscountCode = $requiresDiscountCode;
215 $this->references = $references;
216 $this->stackingMode = $stackingMode;
217 $this->custom = $custom;
218 $this->discountGroup = $discountGroup;
219 }
220
227 public function getId()
228 {
229 if (is_null($this->id)) {
231 $data = $this->raw(self::FIELD_ID);
232 if (is_null($data)) {
233 return null;
234 }
235 $this->id = (string) $data;
236 }
237
238 return $this->id;
239 }
240
247 public function getVersion()
248 {
249 if (is_null($this->version)) {
251 $data = $this->raw(self::FIELD_VERSION);
252 if (is_null($data)) {
253 return null;
254 }
255 $this->version = (int) $data;
256 }
257
258 return $this->version;
259 }
260
267 public function getCreatedAt()
268 {
269 if (is_null($this->createdAt)) {
271 $data = $this->raw(self::FIELD_CREATED_AT);
272 if (is_null($data)) {
273 return null;
274 }
275 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
276 if (false === $data) {
277 return null;
278 }
279 $this->createdAt = $data;
280 }
281
282 return $this->createdAt;
283 }
284
291 public function getLastModifiedAt()
292 {
293 if (is_null($this->lastModifiedAt)) {
295 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
296 if (is_null($data)) {
297 return null;
298 }
299 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
300 if (false === $data) {
301 return null;
302 }
303 $this->lastModifiedAt = $data;
304 }
305
307 }
308
315 public function getLastModifiedBy()
316 {
317 if (is_null($this->lastModifiedBy)) {
319 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
320 if (is_null($data)) {
321 return null;
322 }
323
324 $this->lastModifiedBy = LastModifiedByModel::of($data);
325 }
326
328 }
329
336 public function getCreatedBy()
337 {
338 if (is_null($this->createdBy)) {
340 $data = $this->raw(self::FIELD_CREATED_BY);
341 if (is_null($data)) {
342 return null;
343 }
344
345 $this->createdBy = CreatedByModel::of($data);
346 }
347
348 return $this->createdBy;
349 }
350
357 public function getName()
358 {
359 if (is_null($this->name)) {
361 $data = $this->raw(self::FIELD_NAME);
362 if (is_null($data)) {
363 return null;
364 }
365
366 $this->name = LocalizedStringModel::of($data);
367 }
368
369 return $this->name;
370 }
371
378 public function getKey()
379 {
380 if (is_null($this->key)) {
382 $data = $this->raw(self::FIELD_KEY);
383 if (is_null($data)) {
384 return null;
385 }
386 $this->key = (string) $data;
387 }
388
389 return $this->key;
390 }
391
398 public function getDescription()
399 {
400 if (is_null($this->description)) {
402 $data = $this->raw(self::FIELD_DESCRIPTION);
403 if (is_null($data)) {
404 return null;
405 }
406
407 $this->description = LocalizedStringModel::of($data);
408 }
409
410 return $this->description;
411 }
412
419 public function getValue()
420 {
421 if (is_null($this->value)) {
423 $data = $this->raw(self::FIELD_VALUE);
424 if (is_null($data)) {
425 return null;
426 }
428 $this->value = $className::of($data);
429 }
430
431 return $this->value;
432 }
433
440 public function getCartPredicate()
441 {
442 if (is_null($this->cartPredicate)) {
444 $data = $this->raw(self::FIELD_CART_PREDICATE);
445 if (is_null($data)) {
446 return null;
447 }
448 $this->cartPredicate = (string) $data;
449 }
450
452 }
453
461 public function getTarget()
462 {
463 if (is_null($this->target)) {
465 $data = $this->raw(self::FIELD_TARGET);
466 if (is_null($data)) {
467 return null;
468 }
470 $this->target = $className::of($data);
471 }
472
473 return $this->target;
474 }
475
484 public function getSortOrder()
485 {
486 if (is_null($this->sortOrder)) {
488 $data = $this->raw(self::FIELD_SORT_ORDER);
489 if (is_null($data)) {
490 return null;
491 }
492 $this->sortOrder = (string) $data;
493 }
494
495 return $this->sortOrder;
496 }
497
507 public function getStores()
508 {
509 if (is_null($this->stores)) {
511 $data = $this->raw(self::FIELD_STORES);
512 if (is_null($data)) {
513 return null;
514 }
515 $this->stores = StoreKeyReferenceCollection::fromArray($data);
516 }
517
518 return $this->stores;
519 }
520
527 public function getIsActive()
528 {
529 if (is_null($this->isActive)) {
531 $data = $this->raw(self::FIELD_IS_ACTIVE);
532 if (is_null($data)) {
533 return null;
534 }
535 $this->isActive = (bool) $data;
536 }
537
538 return $this->isActive;
539 }
540
547 public function getValidFrom()
548 {
549 if (is_null($this->validFrom)) {
551 $data = $this->raw(self::FIELD_VALID_FROM);
552 if (is_null($data)) {
553 return null;
554 }
555 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
556 if (false === $data) {
557 return null;
558 }
559 $this->validFrom = $data;
560 }
561
562 return $this->validFrom;
563 }
564
571 public function getValidUntil()
572 {
573 if (is_null($this->validUntil)) {
575 $data = $this->raw(self::FIELD_VALID_UNTIL);
576 if (is_null($data)) {
577 return null;
578 }
579 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
580 if (false === $data) {
581 return null;
582 }
583 $this->validUntil = $data;
584 }
585
586 return $this->validUntil;
587 }
588
595 public function getRequiresDiscountCode()
596 {
597 if (is_null($this->requiresDiscountCode)) {
599 $data = $this->raw(self::FIELD_REQUIRES_DISCOUNT_CODE);
600 if (is_null($data)) {
601 return null;
602 }
603 $this->requiresDiscountCode = (bool) $data;
604 }
605
607 }
608
616 public function getReferences()
617 {
618 if (is_null($this->references)) {
620 $data = $this->raw(self::FIELD_REFERENCES);
621 if (is_null($data)) {
622 return null;
623 }
624 $this->references = ReferenceCollection::fromArray($data);
625 }
626
627 return $this->references;
628 }
629
636 public function getStackingMode()
637 {
638 if (is_null($this->stackingMode)) {
640 $data = $this->raw(self::FIELD_STACKING_MODE);
641 if (is_null($data)) {
642 return null;
643 }
644 $this->stackingMode = (string) $data;
645 }
646
647 return $this->stackingMode;
648 }
649
656 public function getCustom()
657 {
658 if (is_null($this->custom)) {
660 $data = $this->raw(self::FIELD_CUSTOM);
661 if (is_null($data)) {
662 return null;
663 }
664
665 $this->custom = CustomFieldsModel::of($data);
666 }
667
668 return $this->custom;
669 }
670
677 public function getDiscountGroup()
678 {
679 if (is_null($this->discountGroup)) {
681 $data = $this->raw(self::FIELD_DISCOUNT_GROUP);
682 if (is_null($data)) {
683 return null;
684 }
685
686 $this->discountGroup = DiscountGroupReferenceModel::of($data);
687 }
688
690 }
691
692
696 public function setId(?string $id): void
697 {
698 $this->id = $id;
699 }
700
704 public function setVersion(?int $version): void
705 {
706 $this->version = $version;
707 }
708
712 public function setCreatedAt(?DateTimeImmutable $createdAt): void
713 {
714 $this->createdAt = $createdAt;
715 }
716
720 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
721 {
722 $this->lastModifiedAt = $lastModifiedAt;
723 }
724
729 {
730 $this->lastModifiedBy = $lastModifiedBy;
731 }
732
736 public function setCreatedBy(?CreatedBy $createdBy): void
737 {
738 $this->createdBy = $createdBy;
739 }
740
744 public function setName(?LocalizedString $name): void
745 {
746 $this->name = $name;
747 }
748
752 public function setKey(?string $key): void
753 {
754 $this->key = $key;
755 }
756
761 {
762 $this->description = $description;
763 }
764
768 public function setValue(?CartDiscountValue $value): void
769 {
770 $this->value = $value;
771 }
772
776 public function setCartPredicate(?string $cartPredicate): void
777 {
778 $this->cartPredicate = $cartPredicate;
779 }
780
784 public function setTarget(?CartDiscountTarget $target): void
785 {
786 $this->target = $target;
787 }
788
792 public function setSortOrder(?string $sortOrder): void
793 {
794 $this->sortOrder = $sortOrder;
795 }
796
801 {
802 $this->stores = $stores;
803 }
804
808 public function setIsActive(?bool $isActive): void
809 {
810 $this->isActive = $isActive;
811 }
812
816 public function setValidFrom(?DateTimeImmutable $validFrom): void
817 {
818 $this->validFrom = $validFrom;
819 }
820
824 public function setValidUntil(?DateTimeImmutable $validUntil): void
825 {
826 $this->validUntil = $validUntil;
827 }
828
833 {
834 $this->requiresDiscountCode = $requiresDiscountCode;
835 }
836
841 {
842 $this->references = $references;
843 }
844
848 public function setStackingMode(?string $stackingMode): void
849 {
850 $this->stackingMode = $stackingMode;
851 }
852
856 public function setCustom(?CustomFields $custom): void
857 {
858 $this->custom = $custom;
859 }
860
865 {
866 $this->discountGroup = $discountGroup;
867 }
868
869
870 #[\ReturnTypeWillChange]
871 public function jsonSerialize()
872 {
873 $data = $this->toArray();
874 if (isset($data[CartDiscount::FIELD_CREATED_AT]) && $data[CartDiscount::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
875 $data[CartDiscount::FIELD_CREATED_AT] = $data[CartDiscount::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
876 }
877
878 if (isset($data[CartDiscount::FIELD_LAST_MODIFIED_AT]) && $data[CartDiscount::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
879 $data[CartDiscount::FIELD_LAST_MODIFIED_AT] = $data[CartDiscount::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
880 }
881
882 if (isset($data[CartDiscount::FIELD_VALID_FROM]) && $data[CartDiscount::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
883 $data[CartDiscount::FIELD_VALID_FROM] = $data[CartDiscount::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
884 }
885
886 if (isset($data[CartDiscount::FIELD_VALID_UNTIL]) && $data[CartDiscount::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
887 $data[CartDiscount::FIELD_VALID_UNTIL] = $data[CartDiscount::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
888 }
889 return (object) $data;
890 }
891}
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?LocalizedString $name=null, ?string $key=null, ?LocalizedString $description=null, ?CartDiscountValue $value=null, ?string $cartPredicate=null, ?CartDiscountTarget $target=null, ?string $sortOrder=null, ?StoreKeyReferenceCollection $stores=null, ?bool $isActive=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?bool $requiresDiscountCode=null, ?ReferenceCollection $references=null, ?string $stackingMode=null, ?CustomFields $custom=null, ?DiscountGroupReference $discountGroup=null)
setDiscountGroup(?DiscountGroupReference $discountGroup)