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
31use DateTimeImmutable;
32use stdClass;
33
37final class CartDiscountModel extends JsonObjectModel implements CartDiscount
38{
43 protected $id;
44
49 protected $version;
50
55 protected $createdAt;
56
61 protected $lastModifiedAt;
62
67 protected $lastModifiedBy;
68
73 protected $createdBy;
74
79 protected $name;
80
85 protected $key;
86
91 protected $description;
92
97 protected $value;
98
103 protected $cartPredicate;
104
109 protected $target;
110
115 protected $sortOrder;
116
121 protected $stores;
122
127 protected $isActive;
128
133 protected $validFrom;
134
139 protected $validUntil;
140
146
151 protected $references;
152
157 protected $stackingMode;
158
163 protected $custom;
164
169 protected $discountGroup;
170
176
177
181 public function __construct(
182 ?string $id = null,
183 ?int $version = null,
184 ?DateTimeImmutable $createdAt = null,
185 ?DateTimeImmutable $lastModifiedAt = null,
187 ?CreatedBy $createdBy = null,
188 ?LocalizedString $name = null,
189 ?string $key = null,
192 ?string $cartPredicate = null,
194 ?string $sortOrder = null,
196 ?bool $isActive = null,
197 ?DateTimeImmutable $validFrom = null,
198 ?DateTimeImmutable $validUntil = null,
199 ?bool $requiresDiscountCode = null,
201 ?string $stackingMode = null,
202 ?CustomFields $custom = null,
205 ) {
206 $this->id = $id;
207 $this->version = $version;
208 $this->createdAt = $createdAt;
209 $this->lastModifiedAt = $lastModifiedAt;
210 $this->lastModifiedBy = $lastModifiedBy;
211 $this->createdBy = $createdBy;
212 $this->name = $name;
213 $this->key = $key;
214 $this->description = $description;
215 $this->value = $value;
216 $this->cartPredicate = $cartPredicate;
217 $this->target = $target;
218 $this->sortOrder = $sortOrder;
219 $this->stores = $stores;
220 $this->isActive = $isActive;
221 $this->validFrom = $validFrom;
222 $this->validUntil = $validUntil;
223 $this->requiresDiscountCode = $requiresDiscountCode;
224 $this->references = $references;
225 $this->stackingMode = $stackingMode;
226 $this->custom = $custom;
227 $this->discountGroup = $discountGroup;
228 $this->recurringOrderScope = $recurringOrderScope;
229 }
230
237 public function getId()
238 {
239 if (is_null($this->id)) {
241 $data = $this->raw(self::FIELD_ID);
242 if (is_null($data)) {
243 return null;
244 }
245 $this->id = (string) $data;
246 }
247
248 return $this->id;
249 }
250
257 public function getVersion()
258 {
259 if (is_null($this->version)) {
261 $data = $this->raw(self::FIELD_VERSION);
262 if (is_null($data)) {
263 return null;
264 }
265 $this->version = (int) $data;
266 }
267
268 return $this->version;
269 }
270
277 public function getCreatedAt()
278 {
279 if (is_null($this->createdAt)) {
281 $data = $this->raw(self::FIELD_CREATED_AT);
282 if (is_null($data)) {
283 return null;
284 }
285 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
286 if (false === $data) {
287 return null;
288 }
289 $this->createdAt = $data;
290 }
291
292 return $this->createdAt;
293 }
294
301 public function getLastModifiedAt()
302 {
303 if (is_null($this->lastModifiedAt)) {
305 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
306 if (is_null($data)) {
307 return null;
308 }
309 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
310 if (false === $data) {
311 return null;
312 }
313 $this->lastModifiedAt = $data;
314 }
315
317 }
318
325 public function getLastModifiedBy()
326 {
327 if (is_null($this->lastModifiedBy)) {
329 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
330 if (is_null($data)) {
331 return null;
332 }
333
334 $this->lastModifiedBy = LastModifiedByModel::of($data);
335 }
336
338 }
339
346 public function getCreatedBy()
347 {
348 if (is_null($this->createdBy)) {
350 $data = $this->raw(self::FIELD_CREATED_BY);
351 if (is_null($data)) {
352 return null;
353 }
354
355 $this->createdBy = CreatedByModel::of($data);
356 }
357
358 return $this->createdBy;
359 }
360
367 public function getName()
368 {
369 if (is_null($this->name)) {
371 $data = $this->raw(self::FIELD_NAME);
372 if (is_null($data)) {
373 return null;
374 }
375
376 $this->name = LocalizedStringModel::of($data);
377 }
378
379 return $this->name;
380 }
381
388 public function getKey()
389 {
390 if (is_null($this->key)) {
392 $data = $this->raw(self::FIELD_KEY);
393 if (is_null($data)) {
394 return null;
395 }
396 $this->key = (string) $data;
397 }
398
399 return $this->key;
400 }
401
408 public function getDescription()
409 {
410 if (is_null($this->description)) {
412 $data = $this->raw(self::FIELD_DESCRIPTION);
413 if (is_null($data)) {
414 return null;
415 }
416
417 $this->description = LocalizedStringModel::of($data);
418 }
419
420 return $this->description;
421 }
422
429 public function getValue()
430 {
431 if (is_null($this->value)) {
433 $data = $this->raw(self::FIELD_VALUE);
434 if (is_null($data)) {
435 return null;
436 }
438 $this->value = $className::of($data);
439 }
440
441 return $this->value;
442 }
443
450 public function getCartPredicate()
451 {
452 if (is_null($this->cartPredicate)) {
454 $data = $this->raw(self::FIELD_CART_PREDICATE);
455 if (is_null($data)) {
456 return null;
457 }
458 $this->cartPredicate = (string) $data;
459 }
460
462 }
463
471 public function getTarget()
472 {
473 if (is_null($this->target)) {
475 $data = $this->raw(self::FIELD_TARGET);
476 if (is_null($data)) {
477 return null;
478 }
480 $this->target = $className::of($data);
481 }
482
483 return $this->target;
484 }
485
494 public function getSortOrder()
495 {
496 if (is_null($this->sortOrder)) {
498 $data = $this->raw(self::FIELD_SORT_ORDER);
499 if (is_null($data)) {
500 return null;
501 }
502 $this->sortOrder = (string) $data;
503 }
504
505 return $this->sortOrder;
506 }
507
517 public function getStores()
518 {
519 if (is_null($this->stores)) {
521 $data = $this->raw(self::FIELD_STORES);
522 if (is_null($data)) {
523 return null;
524 }
525 $this->stores = StoreKeyReferenceCollection::fromArray($data);
526 }
527
528 return $this->stores;
529 }
530
537 public function getIsActive()
538 {
539 if (is_null($this->isActive)) {
541 $data = $this->raw(self::FIELD_IS_ACTIVE);
542 if (is_null($data)) {
543 return null;
544 }
545 $this->isActive = (bool) $data;
546 }
547
548 return $this->isActive;
549 }
550
557 public function getValidFrom()
558 {
559 if (is_null($this->validFrom)) {
561 $data = $this->raw(self::FIELD_VALID_FROM);
562 if (is_null($data)) {
563 return null;
564 }
565 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
566 if (false === $data) {
567 return null;
568 }
569 $this->validFrom = $data;
570 }
571
572 return $this->validFrom;
573 }
574
581 public function getValidUntil()
582 {
583 if (is_null($this->validUntil)) {
585 $data = $this->raw(self::FIELD_VALID_UNTIL);
586 if (is_null($data)) {
587 return null;
588 }
589 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
590 if (false === $data) {
591 return null;
592 }
593 $this->validUntil = $data;
594 }
595
596 return $this->validUntil;
597 }
598
605 public function getRequiresDiscountCode()
606 {
607 if (is_null($this->requiresDiscountCode)) {
609 $data = $this->raw(self::FIELD_REQUIRES_DISCOUNT_CODE);
610 if (is_null($data)) {
611 return null;
612 }
613 $this->requiresDiscountCode = (bool) $data;
614 }
615
617 }
618
626 public function getReferences()
627 {
628 if (is_null($this->references)) {
630 $data = $this->raw(self::FIELD_REFERENCES);
631 if (is_null($data)) {
632 return null;
633 }
634 $this->references = ReferenceCollection::fromArray($data);
635 }
636
637 return $this->references;
638 }
639
646 public function getStackingMode()
647 {
648 if (is_null($this->stackingMode)) {
650 $data = $this->raw(self::FIELD_STACKING_MODE);
651 if (is_null($data)) {
652 return null;
653 }
654 $this->stackingMode = (string) $data;
655 }
656
657 return $this->stackingMode;
658 }
659
666 public function getCustom()
667 {
668 if (is_null($this->custom)) {
670 $data = $this->raw(self::FIELD_CUSTOM);
671 if (is_null($data)) {
672 return null;
673 }
674
675 $this->custom = CustomFieldsModel::of($data);
676 }
677
678 return $this->custom;
679 }
680
687 public function getDiscountGroup()
688 {
689 if (is_null($this->discountGroup)) {
691 $data = $this->raw(self::FIELD_DISCOUNT_GROUP);
692 if (is_null($data)) {
693 return null;
694 }
695
696 $this->discountGroup = DiscountGroupReferenceModel::of($data);
697 }
698
700 }
701
709 public function getRecurringOrderScope()
710 {
711 if (is_null($this->recurringOrderScope)) {
713 $data = $this->raw(self::FIELD_RECURRING_ORDER_SCOPE);
714 if (is_null($data)) {
715 return null;
716 }
718 $this->recurringOrderScope = $className::of($data);
719 }
720
722 }
723
724
728 public function setId(?string $id): void
729 {
730 $this->id = $id;
731 }
732
736 public function setVersion(?int $version): void
737 {
738 $this->version = $version;
739 }
740
744 public function setCreatedAt(?DateTimeImmutable $createdAt): void
745 {
746 $this->createdAt = $createdAt;
747 }
748
752 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
753 {
754 $this->lastModifiedAt = $lastModifiedAt;
755 }
756
761 {
762 $this->lastModifiedBy = $lastModifiedBy;
763 }
764
768 public function setCreatedBy(?CreatedBy $createdBy): void
769 {
770 $this->createdBy = $createdBy;
771 }
772
776 public function setName(?LocalizedString $name): void
777 {
778 $this->name = $name;
779 }
780
784 public function setKey(?string $key): void
785 {
786 $this->key = $key;
787 }
788
793 {
794 $this->description = $description;
795 }
796
800 public function setValue(?CartDiscountValue $value): void
801 {
802 $this->value = $value;
803 }
804
808 public function setCartPredicate(?string $cartPredicate): void
809 {
810 $this->cartPredicate = $cartPredicate;
811 }
812
816 public function setTarget(?CartDiscountTarget $target): void
817 {
818 $this->target = $target;
819 }
820
824 public function setSortOrder(?string $sortOrder): void
825 {
826 $this->sortOrder = $sortOrder;
827 }
828
833 {
834 $this->stores = $stores;
835 }
836
840 public function setIsActive(?bool $isActive): void
841 {
842 $this->isActive = $isActive;
843 }
844
848 public function setValidFrom(?DateTimeImmutable $validFrom): void
849 {
850 $this->validFrom = $validFrom;
851 }
852
856 public function setValidUntil(?DateTimeImmutable $validUntil): void
857 {
858 $this->validUntil = $validUntil;
859 }
860
865 {
866 $this->requiresDiscountCode = $requiresDiscountCode;
867 }
868
873 {
874 $this->references = $references;
875 }
876
880 public function setStackingMode(?string $stackingMode): void
881 {
882 $this->stackingMode = $stackingMode;
883 }
884
888 public function setCustom(?CustomFields $custom): void
889 {
890 $this->custom = $custom;
891 }
892
897 {
898 $this->discountGroup = $discountGroup;
899 }
900
905 {
906 $this->recurringOrderScope = $recurringOrderScope;
907 }
908
909
910 #[\ReturnTypeWillChange]
911 public function jsonSerialize()
912 {
913 $data = $this->toArray();
914 if (isset($data[CartDiscount::FIELD_CREATED_AT]) && $data[CartDiscount::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
915 $data[CartDiscount::FIELD_CREATED_AT] = $data[CartDiscount::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
916 }
917
918 if (isset($data[CartDiscount::FIELD_LAST_MODIFIED_AT]) && $data[CartDiscount::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
919 $data[CartDiscount::FIELD_LAST_MODIFIED_AT] = $data[CartDiscount::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
920 }
921
922 if (isset($data[CartDiscount::FIELD_VALID_FROM]) && $data[CartDiscount::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
923 $data[CartDiscount::FIELD_VALID_FROM] = $data[CartDiscount::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
924 }
925
926 if (isset($data[CartDiscount::FIELD_VALID_UNTIL]) && $data[CartDiscount::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
927 $data[CartDiscount::FIELD_VALID_UNTIL] = $data[CartDiscount::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
928 }
929 return (object) $data;
930 }
931}
__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, ?RecurringOrderScope $recurringOrderScope=null)
setDiscountGroup(?DiscountGroupReference $discountGroup)
setRecurringOrderScope(?RecurringOrderScope $recurringOrderScope)