commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
DiscountCodeModel.php
1<?php
2
3declare(strict_types=1);
10
28use DateTimeImmutable;
29use stdClass;
30
34final class DiscountCodeModel extends JsonObjectModel implements DiscountCode
35{
40 protected $id;
41
46 protected $version;
47
52 protected $createdAt;
53
58 protected $lastModifiedAt;
59
64 protected $key;
65
70 protected $lastModifiedBy;
71
76 protected $createdBy;
77
82 protected $name;
83
88 protected $description;
89
94 protected $code;
95
100 protected $cartDiscounts;
101
106 protected $stores;
107
112 protected $cartPredicate;
113
118 protected $isActive;
119
124 protected $references;
125
131
137
142 protected $custom;
143
148 protected $groups;
149
154 protected $validFrom;
155
160 protected $validUntil;
161
167
168
172 public function __construct(
173 ?string $id = null,
174 ?int $version = null,
175 ?DateTimeImmutable $createdAt = null,
176 ?DateTimeImmutable $lastModifiedAt = null,
177 ?string $key = null,
179 ?CreatedBy $createdBy = null,
180 ?LocalizedString $name = null,
182 ?string $code = null,
185 ?string $cartPredicate = null,
186 ?bool $isActive = null,
188 ?int $maxApplications = null,
189 ?int $maxApplicationsPerCustomer = null,
190 ?CustomFields $custom = null,
191 ?array $groups = null,
192 ?DateTimeImmutable $validFrom = null,
193 ?DateTimeImmutable $validUntil = null,
194 ?int $applicationVersion = null
195 ) {
196 $this->id = $id;
197 $this->version = $version;
198 $this->createdAt = $createdAt;
199 $this->lastModifiedAt = $lastModifiedAt;
200 $this->key = $key;
201 $this->lastModifiedBy = $lastModifiedBy;
202 $this->createdBy = $createdBy;
203 $this->name = $name;
204 $this->description = $description;
205 $this->code = $code;
206 $this->cartDiscounts = $cartDiscounts;
207 $this->stores = $stores;
208 $this->cartPredicate = $cartPredicate;
209 $this->isActive = $isActive;
210 $this->references = $references;
211 $this->maxApplications = $maxApplications;
212 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
213 $this->custom = $custom;
214 $this->groups = $groups;
215 $this->validFrom = $validFrom;
216 $this->validUntil = $validUntil;
217 $this->applicationVersion = $applicationVersion;
218 }
219
226 public function getId()
227 {
228 if (is_null($this->id)) {
230 $data = $this->raw(self::FIELD_ID);
231 if (is_null($data)) {
232 return null;
233 }
234 $this->id = (string) $data;
235 }
236
237 return $this->id;
238 }
239
246 public function getVersion()
247 {
248 if (is_null($this->version)) {
250 $data = $this->raw(self::FIELD_VERSION);
251 if (is_null($data)) {
252 return null;
253 }
254 $this->version = (int) $data;
255 }
256
257 return $this->version;
258 }
259
266 public function getCreatedAt()
267 {
268 if (is_null($this->createdAt)) {
270 $data = $this->raw(self::FIELD_CREATED_AT);
271 if (is_null($data)) {
272 return null;
273 }
274 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
275 if (false === $data) {
276 return null;
277 }
278 $this->createdAt = $data;
279 }
280
281 return $this->createdAt;
282 }
283
290 public function getLastModifiedAt()
291 {
292 if (is_null($this->lastModifiedAt)) {
294 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
295 if (is_null($data)) {
296 return null;
297 }
298 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
299 if (false === $data) {
300 return null;
301 }
302 $this->lastModifiedAt = $data;
303 }
304
306 }
307
314 public function getKey()
315 {
316 if (is_null($this->key)) {
318 $data = $this->raw(self::FIELD_KEY);
319 if (is_null($data)) {
320 return null;
321 }
322 $this->key = (string) $data;
323 }
324
325 return $this->key;
326 }
327
334 public function getLastModifiedBy()
335 {
336 if (is_null($this->lastModifiedBy)) {
338 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
339 if (is_null($data)) {
340 return null;
341 }
342
343 $this->lastModifiedBy = LastModifiedByModel::of($data);
344 }
345
347 }
348
355 public function getCreatedBy()
356 {
357 if (is_null($this->createdBy)) {
359 $data = $this->raw(self::FIELD_CREATED_BY);
360 if (is_null($data)) {
361 return null;
362 }
363
364 $this->createdBy = CreatedByModel::of($data);
365 }
366
367 return $this->createdBy;
368 }
369
376 public function getName()
377 {
378 if (is_null($this->name)) {
380 $data = $this->raw(self::FIELD_NAME);
381 if (is_null($data)) {
382 return null;
383 }
384
385 $this->name = LocalizedStringModel::of($data);
386 }
387
388 return $this->name;
389 }
390
397 public function getDescription()
398 {
399 if (is_null($this->description)) {
401 $data = $this->raw(self::FIELD_DESCRIPTION);
402 if (is_null($data)) {
403 return null;
404 }
405
406 $this->description = LocalizedStringModel::of($data);
407 }
408
409 return $this->description;
410 }
411
418 public function getCode()
419 {
420 if (is_null($this->code)) {
422 $data = $this->raw(self::FIELD_CODE);
423 if (is_null($data)) {
424 return null;
425 }
426 $this->code = (string) $data;
427 }
428
429 return $this->code;
430 }
431
438 public function getCartDiscounts()
439 {
440 if (is_null($this->cartDiscounts)) {
442 $data = $this->raw(self::FIELD_CART_DISCOUNTS);
443 if (is_null($data)) {
444 return null;
445 }
446 $this->cartDiscounts = CartDiscountReferenceCollection::fromArray($data);
447 }
448
450 }
451
459 public function getStores()
460 {
461 if (is_null($this->stores)) {
463 $data = $this->raw(self::FIELD_STORES);
464 if (is_null($data)) {
465 return null;
466 }
467 $this->stores = StoreKeyReferenceCollection::fromArray($data);
468 }
469
470 return $this->stores;
471 }
472
479 public function getCartPredicate()
480 {
481 if (is_null($this->cartPredicate)) {
483 $data = $this->raw(self::FIELD_CART_PREDICATE);
484 if (is_null($data)) {
485 return null;
486 }
487 $this->cartPredicate = (string) $data;
488 }
489
491 }
492
499 public function getIsActive()
500 {
501 if (is_null($this->isActive)) {
503 $data = $this->raw(self::FIELD_IS_ACTIVE);
504 if (is_null($data)) {
505 return null;
506 }
507 $this->isActive = (bool) $data;
508 }
509
510 return $this->isActive;
511 }
512
520 public function getReferences()
521 {
522 if (is_null($this->references)) {
524 $data = $this->raw(self::FIELD_REFERENCES);
525 if (is_null($data)) {
526 return null;
527 }
528 $this->references = ReferenceCollection::fromArray($data);
529 }
530
531 return $this->references;
532 }
533
543 public function getMaxApplications()
544 {
545 if (is_null($this->maxApplications)) {
547 $data = $this->raw(self::FIELD_MAX_APPLICATIONS);
548 if (is_null($data)) {
549 return null;
550 }
551 $this->maxApplications = (int) $data;
552 }
553
555 }
556
567 {
568 if (is_null($this->maxApplicationsPerCustomer)) {
570 $data = $this->raw(self::FIELD_MAX_APPLICATIONS_PER_CUSTOMER);
571 if (is_null($data)) {
572 return null;
573 }
574 $this->maxApplicationsPerCustomer = (int) $data;
575 }
576
578 }
579
586 public function getCustom()
587 {
588 if (is_null($this->custom)) {
590 $data = $this->raw(self::FIELD_CUSTOM);
591 if (is_null($data)) {
592 return null;
593 }
594
595 $this->custom = CustomFieldsModel::of($data);
596 }
597
598 return $this->custom;
599 }
600
607 public function getGroups()
608 {
609 if (is_null($this->groups)) {
611 $data = $this->raw(self::FIELD_GROUPS);
612 if (is_null($data)) {
613 return null;
614 }
615 $this->groups = $data;
616 }
617
618 return $this->groups;
619 }
620
627 public function getValidFrom()
628 {
629 if (is_null($this->validFrom)) {
631 $data = $this->raw(self::FIELD_VALID_FROM);
632 if (is_null($data)) {
633 return null;
634 }
635 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
636 if (false === $data) {
637 return null;
638 }
639 $this->validFrom = $data;
640 }
641
642 return $this->validFrom;
643 }
644
651 public function getValidUntil()
652 {
653 if (is_null($this->validUntil)) {
655 $data = $this->raw(self::FIELD_VALID_UNTIL);
656 if (is_null($data)) {
657 return null;
658 }
659 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
660 if (false === $data) {
661 return null;
662 }
663 $this->validUntil = $data;
664 }
665
666 return $this->validUntil;
667 }
668
676 public function getApplicationVersion()
677 {
678 if (is_null($this->applicationVersion)) {
680 $data = $this->raw(self::FIELD_APPLICATION_VERSION);
681 if (is_null($data)) {
682 return null;
683 }
684 $this->applicationVersion = (int) $data;
685 }
686
688 }
689
690
694 public function setId(?string $id): void
695 {
696 $this->id = $id;
697 }
698
702 public function setVersion(?int $version): void
703 {
704 $this->version = $version;
705 }
706
710 public function setCreatedAt(?DateTimeImmutable $createdAt): void
711 {
712 $this->createdAt = $createdAt;
713 }
714
718 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
719 {
720 $this->lastModifiedAt = $lastModifiedAt;
721 }
722
726 public function setKey(?string $key): void
727 {
728 $this->key = $key;
729 }
730
735 {
736 $this->lastModifiedBy = $lastModifiedBy;
737 }
738
742 public function setCreatedBy(?CreatedBy $createdBy): void
743 {
744 $this->createdBy = $createdBy;
745 }
746
750 public function setName(?LocalizedString $name): void
751 {
752 $this->name = $name;
753 }
754
759 {
760 $this->description = $description;
761 }
762
766 public function setCode(?string $code): void
767 {
768 $this->code = $code;
769 }
770
775 {
776 $this->cartDiscounts = $cartDiscounts;
777 }
778
783 {
784 $this->stores = $stores;
785 }
786
790 public function setCartPredicate(?string $cartPredicate): void
791 {
792 $this->cartPredicate = $cartPredicate;
793 }
794
798 public function setIsActive(?bool $isActive): void
799 {
800 $this->isActive = $isActive;
801 }
802
807 {
808 $this->references = $references;
809 }
810
814 public function setMaxApplications(?int $maxApplications): void
815 {
816 $this->maxApplications = $maxApplications;
817 }
818
823 {
824 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
825 }
826
830 public function setCustom(?CustomFields $custom): void
831 {
832 $this->custom = $custom;
833 }
834
838 public function setGroups(?array $groups): void
839 {
840 $this->groups = $groups;
841 }
842
846 public function setValidFrom(?DateTimeImmutable $validFrom): void
847 {
848 $this->validFrom = $validFrom;
849 }
850
854 public function setValidUntil(?DateTimeImmutable $validUntil): void
855 {
856 $this->validUntil = $validUntil;
857 }
858
862 public function setApplicationVersion(?int $applicationVersion): void
863 {
864 $this->applicationVersion = $applicationVersion;
865 }
866
867
868 #[\ReturnTypeWillChange]
869 public function jsonSerialize()
870 {
871 $data = $this->toArray();
872 if (isset($data[DiscountCode::FIELD_CREATED_AT]) && $data[DiscountCode::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
873 $data[DiscountCode::FIELD_CREATED_AT] = $data[DiscountCode::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
874 }
875
876 if (isset($data[DiscountCode::FIELD_LAST_MODIFIED_AT]) && $data[DiscountCode::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
877 $data[DiscountCode::FIELD_LAST_MODIFIED_AT] = $data[DiscountCode::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
878 }
879
880 if (isset($data[DiscountCode::FIELD_VALID_FROM]) && $data[DiscountCode::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
881 $data[DiscountCode::FIELD_VALID_FROM] = $data[DiscountCode::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
882 }
883
884 if (isset($data[DiscountCode::FIELD_VALID_UNTIL]) && $data[DiscountCode::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
885 $data[DiscountCode::FIELD_VALID_UNTIL] = $data[DiscountCode::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
886 }
887 return (object) $data;
888 }
889}
setMaxApplicationsPerCustomer(?int $maxApplicationsPerCustomer)
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?string $key=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?LocalizedString $name=null, ?LocalizedString $description=null, ?string $code=null, ?CartDiscountReferenceCollection $cartDiscounts=null, ?StoreKeyReferenceCollection $stores=null, ?string $cartPredicate=null, ?bool $isActive=null, ?ReferenceCollection $references=null, ?int $maxApplications=null, ?int $maxApplicationsPerCustomer=null, ?CustomFields $custom=null, ?array $groups=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?int $applicationVersion=null)
setCartDiscounts(?CartDiscountReferenceCollection $cartDiscounts)