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
27use DateTimeImmutable;
28use stdClass;
29
33final class DiscountCodeModel extends JsonObjectModel implements DiscountCode
34{
39 protected $id;
40
45 protected $version;
46
51 protected $createdAt;
52
57 protected $lastModifiedAt;
58
63 protected $key;
64
69 protected $lastModifiedBy;
70
75 protected $createdBy;
76
81 protected $name;
82
87 protected $description;
88
93 protected $code;
94
99 protected $cartDiscounts;
100
105 protected $cartPredicate;
106
111 protected $isActive;
112
117 protected $references;
118
124
130
135 protected $custom;
136
141 protected $groups;
142
147 protected $validFrom;
148
153 protected $validUntil;
154
160
161
165 public function __construct(
166 ?string $id = null,
167 ?int $version = null,
168 ?DateTimeImmutable $createdAt = null,
169 ?DateTimeImmutable $lastModifiedAt = null,
170 ?string $key = null,
172 ?CreatedBy $createdBy = null,
173 ?LocalizedString $name = null,
175 ?string $code = null,
177 ?string $cartPredicate = null,
178 ?bool $isActive = null,
180 ?int $maxApplications = null,
181 ?int $maxApplicationsPerCustomer = null,
182 ?CustomFields $custom = null,
183 ?array $groups = null,
184 ?DateTimeImmutable $validFrom = null,
185 ?DateTimeImmutable $validUntil = null,
186 ?int $applicationVersion = null
187 ) {
188 $this->id = $id;
189 $this->version = $version;
190 $this->createdAt = $createdAt;
191 $this->lastModifiedAt = $lastModifiedAt;
192 $this->key = $key;
193 $this->lastModifiedBy = $lastModifiedBy;
194 $this->createdBy = $createdBy;
195 $this->name = $name;
196 $this->description = $description;
197 $this->code = $code;
198 $this->cartDiscounts = $cartDiscounts;
199 $this->cartPredicate = $cartPredicate;
200 $this->isActive = $isActive;
201 $this->references = $references;
202 $this->maxApplications = $maxApplications;
203 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
204 $this->custom = $custom;
205 $this->groups = $groups;
206 $this->validFrom = $validFrom;
207 $this->validUntil = $validUntil;
208 $this->applicationVersion = $applicationVersion;
209 }
210
217 public function getId()
218 {
219 if (is_null($this->id)) {
221 $data = $this->raw(self::FIELD_ID);
222 if (is_null($data)) {
223 return null;
224 }
225 $this->id = (string) $data;
226 }
227
228 return $this->id;
229 }
230
237 public function getVersion()
238 {
239 if (is_null($this->version)) {
241 $data = $this->raw(self::FIELD_VERSION);
242 if (is_null($data)) {
243 return null;
244 }
245 $this->version = (int) $data;
246 }
247
248 return $this->version;
249 }
250
257 public function getCreatedAt()
258 {
259 if (is_null($this->createdAt)) {
261 $data = $this->raw(self::FIELD_CREATED_AT);
262 if (is_null($data)) {
263 return null;
264 }
265 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
266 if (false === $data) {
267 return null;
268 }
269 $this->createdAt = $data;
270 }
271
272 return $this->createdAt;
273 }
274
281 public function getLastModifiedAt()
282 {
283 if (is_null($this->lastModifiedAt)) {
285 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
286 if (is_null($data)) {
287 return null;
288 }
289 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
290 if (false === $data) {
291 return null;
292 }
293 $this->lastModifiedAt = $data;
294 }
295
297 }
298
305 public function getKey()
306 {
307 if (is_null($this->key)) {
309 $data = $this->raw(self::FIELD_KEY);
310 if (is_null($data)) {
311 return null;
312 }
313 $this->key = (string) $data;
314 }
315
316 return $this->key;
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 getDescription()
389 {
390 if (is_null($this->description)) {
392 $data = $this->raw(self::FIELD_DESCRIPTION);
393 if (is_null($data)) {
394 return null;
395 }
396
397 $this->description = LocalizedStringModel::of($data);
398 }
399
400 return $this->description;
401 }
402
409 public function getCode()
410 {
411 if (is_null($this->code)) {
413 $data = $this->raw(self::FIELD_CODE);
414 if (is_null($data)) {
415 return null;
416 }
417 $this->code = (string) $data;
418 }
419
420 return $this->code;
421 }
422
429 public function getCartDiscounts()
430 {
431 if (is_null($this->cartDiscounts)) {
433 $data = $this->raw(self::FIELD_CART_DISCOUNTS);
434 if (is_null($data)) {
435 return null;
436 }
437 $this->cartDiscounts = CartDiscountReferenceCollection::fromArray($data);
438 }
439
441 }
442
449 public function getCartPredicate()
450 {
451 if (is_null($this->cartPredicate)) {
453 $data = $this->raw(self::FIELD_CART_PREDICATE);
454 if (is_null($data)) {
455 return null;
456 }
457 $this->cartPredicate = (string) $data;
458 }
459
461 }
462
469 public function getIsActive()
470 {
471 if (is_null($this->isActive)) {
473 $data = $this->raw(self::FIELD_IS_ACTIVE);
474 if (is_null($data)) {
475 return null;
476 }
477 $this->isActive = (bool) $data;
478 }
479
480 return $this->isActive;
481 }
482
490 public function getReferences()
491 {
492 if (is_null($this->references)) {
494 $data = $this->raw(self::FIELD_REFERENCES);
495 if (is_null($data)) {
496 return null;
497 }
498 $this->references = ReferenceCollection::fromArray($data);
499 }
500
501 return $this->references;
502 }
503
512 public function getMaxApplications()
513 {
514 if (is_null($this->maxApplications)) {
516 $data = $this->raw(self::FIELD_MAX_APPLICATIONS);
517 if (is_null($data)) {
518 return null;
519 }
520 $this->maxApplications = (int) $data;
521 }
522
524 }
525
535 {
536 if (is_null($this->maxApplicationsPerCustomer)) {
538 $data = $this->raw(self::FIELD_MAX_APPLICATIONS_PER_CUSTOMER);
539 if (is_null($data)) {
540 return null;
541 }
542 $this->maxApplicationsPerCustomer = (int) $data;
543 }
544
546 }
547
554 public function getCustom()
555 {
556 if (is_null($this->custom)) {
558 $data = $this->raw(self::FIELD_CUSTOM);
559 if (is_null($data)) {
560 return null;
561 }
562
563 $this->custom = CustomFieldsModel::of($data);
564 }
565
566 return $this->custom;
567 }
568
575 public function getGroups()
576 {
577 if (is_null($this->groups)) {
579 $data = $this->raw(self::FIELD_GROUPS);
580 if (is_null($data)) {
581 return null;
582 }
583 $this->groups = $data;
584 }
585
586 return $this->groups;
587 }
588
595 public function getValidFrom()
596 {
597 if (is_null($this->validFrom)) {
599 $data = $this->raw(self::FIELD_VALID_FROM);
600 if (is_null($data)) {
601 return null;
602 }
603 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
604 if (false === $data) {
605 return null;
606 }
607 $this->validFrom = $data;
608 }
609
610 return $this->validFrom;
611 }
612
619 public function getValidUntil()
620 {
621 if (is_null($this->validUntil)) {
623 $data = $this->raw(self::FIELD_VALID_UNTIL);
624 if (is_null($data)) {
625 return null;
626 }
627 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
628 if (false === $data) {
629 return null;
630 }
631 $this->validUntil = $data;
632 }
633
634 return $this->validUntil;
635 }
636
644 public function getApplicationVersion()
645 {
646 if (is_null($this->applicationVersion)) {
648 $data = $this->raw(self::FIELD_APPLICATION_VERSION);
649 if (is_null($data)) {
650 return null;
651 }
652 $this->applicationVersion = (int) $data;
653 }
654
656 }
657
658
662 public function setId(?string $id): void
663 {
664 $this->id = $id;
665 }
666
670 public function setVersion(?int $version): void
671 {
672 $this->version = $version;
673 }
674
678 public function setCreatedAt(?DateTimeImmutable $createdAt): void
679 {
680 $this->createdAt = $createdAt;
681 }
682
686 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
687 {
688 $this->lastModifiedAt = $lastModifiedAt;
689 }
690
694 public function setKey(?string $key): void
695 {
696 $this->key = $key;
697 }
698
703 {
704 $this->lastModifiedBy = $lastModifiedBy;
705 }
706
710 public function setCreatedBy(?CreatedBy $createdBy): void
711 {
712 $this->createdBy = $createdBy;
713 }
714
718 public function setName(?LocalizedString $name): void
719 {
720 $this->name = $name;
721 }
722
727 {
728 $this->description = $description;
729 }
730
734 public function setCode(?string $code): void
735 {
736 $this->code = $code;
737 }
738
743 {
744 $this->cartDiscounts = $cartDiscounts;
745 }
746
750 public function setCartPredicate(?string $cartPredicate): void
751 {
752 $this->cartPredicate = $cartPredicate;
753 }
754
758 public function setIsActive(?bool $isActive): void
759 {
760 $this->isActive = $isActive;
761 }
762
767 {
768 $this->references = $references;
769 }
770
774 public function setMaxApplications(?int $maxApplications): void
775 {
776 $this->maxApplications = $maxApplications;
777 }
778
783 {
784 $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
785 }
786
790 public function setCustom(?CustomFields $custom): void
791 {
792 $this->custom = $custom;
793 }
794
798 public function setGroups(?array $groups): void
799 {
800 $this->groups = $groups;
801 }
802
806 public function setValidFrom(?DateTimeImmutable $validFrom): void
807 {
808 $this->validFrom = $validFrom;
809 }
810
814 public function setValidUntil(?DateTimeImmutable $validUntil): void
815 {
816 $this->validUntil = $validUntil;
817 }
818
822 public function setApplicationVersion(?int $applicationVersion): void
823 {
824 $this->applicationVersion = $applicationVersion;
825 }
826
827
828 #[\ReturnTypeWillChange]
829 public function jsonSerialize()
830 {
831 $data = $this->toArray();
832 if (isset($data[DiscountCode::FIELD_CREATED_AT]) && $data[DiscountCode::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
833 $data[DiscountCode::FIELD_CREATED_AT] = $data[DiscountCode::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
834 }
835
836 if (isset($data[DiscountCode::FIELD_LAST_MODIFIED_AT]) && $data[DiscountCode::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
837 $data[DiscountCode::FIELD_LAST_MODIFIED_AT] = $data[DiscountCode::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
838 }
839
840 if (isset($data[DiscountCode::FIELD_VALID_FROM]) && $data[DiscountCode::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
841 $data[DiscountCode::FIELD_VALID_FROM] = $data[DiscountCode::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
842 }
843
844 if (isset($data[DiscountCode::FIELD_VALID_UNTIL]) && $data[DiscountCode::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
845 $data[DiscountCode::FIELD_VALID_UNTIL] = $data[DiscountCode::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
846 }
847 return (object) $data;
848 }
849}
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, ?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)