commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
DiscountCodeModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
27 use DateTimeImmutable;
28 use stdClass;
29 
33 final 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 
123  protected $maxApplications;
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 
296  return $this->lastModifiedAt;
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 
337  return $this->lastModifiedBy;
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 
440  return $this->cartDiscounts;
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 
460  return $this->cartPredicate;
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 
511  public function getMaxApplications()
512  {
513  if (is_null($this->maxApplications)) {
515  $data = $this->raw(self::FIELD_MAX_APPLICATIONS);
516  if (is_null($data)) {
517  return null;
518  }
519  $this->maxApplications = (int) $data;
520  }
521 
522  return $this->maxApplications;
523  }
524 
533  {
534  if (is_null($this->maxApplicationsPerCustomer)) {
536  $data = $this->raw(self::FIELD_MAX_APPLICATIONS_PER_CUSTOMER);
537  if (is_null($data)) {
538  return null;
539  }
540  $this->maxApplicationsPerCustomer = (int) $data;
541  }
542 
544  }
545 
552  public function getCustom()
553  {
554  if (is_null($this->custom)) {
556  $data = $this->raw(self::FIELD_CUSTOM);
557  if (is_null($data)) {
558  return null;
559  }
560 
561  $this->custom = CustomFieldsModel::of($data);
562  }
563 
564  return $this->custom;
565  }
566 
573  public function getGroups()
574  {
575  if (is_null($this->groups)) {
577  $data = $this->raw(self::FIELD_GROUPS);
578  if (is_null($data)) {
579  return null;
580  }
581  $this->groups = $data;
582  }
583 
584  return $this->groups;
585  }
586 
593  public function getValidFrom()
594  {
595  if (is_null($this->validFrom)) {
597  $data = $this->raw(self::FIELD_VALID_FROM);
598  if (is_null($data)) {
599  return null;
600  }
601  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
602  if (false === $data) {
603  return null;
604  }
605  $this->validFrom = $data;
606  }
607 
608  return $this->validFrom;
609  }
610 
617  public function getValidUntil()
618  {
619  if (is_null($this->validUntil)) {
621  $data = $this->raw(self::FIELD_VALID_UNTIL);
622  if (is_null($data)) {
623  return null;
624  }
625  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
626  if (false === $data) {
627  return null;
628  }
629  $this->validUntil = $data;
630  }
631 
632  return $this->validUntil;
633  }
634 
642  public function getApplicationVersion()
643  {
644  if (is_null($this->applicationVersion)) {
646  $data = $this->raw(self::FIELD_APPLICATION_VERSION);
647  if (is_null($data)) {
648  return null;
649  }
650  $this->applicationVersion = (int) $data;
651  }
652 
654  }
655 
656 
660  public function setId(?string $id): void
661  {
662  $this->id = $id;
663  }
664 
668  public function setVersion(?int $version): void
669  {
670  $this->version = $version;
671  }
672 
676  public function setCreatedAt(?DateTimeImmutable $createdAt): void
677  {
678  $this->createdAt = $createdAt;
679  }
680 
684  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
685  {
686  $this->lastModifiedAt = $lastModifiedAt;
687  }
688 
692  public function setKey(?string $key): void
693  {
694  $this->key = $key;
695  }
696 
701  {
702  $this->lastModifiedBy = $lastModifiedBy;
703  }
704 
708  public function setCreatedBy(?CreatedBy $createdBy): void
709  {
710  $this->createdBy = $createdBy;
711  }
712 
716  public function setName(?LocalizedString $name): void
717  {
718  $this->name = $name;
719  }
720 
725  {
726  $this->description = $description;
727  }
728 
732  public function setCode(?string $code): void
733  {
734  $this->code = $code;
735  }
736 
741  {
742  $this->cartDiscounts = $cartDiscounts;
743  }
744 
748  public function setCartPredicate(?string $cartPredicate): void
749  {
750  $this->cartPredicate = $cartPredicate;
751  }
752 
756  public function setIsActive(?bool $isActive): void
757  {
758  $this->isActive = $isActive;
759  }
760 
765  {
766  $this->references = $references;
767  }
768 
772  public function setMaxApplications(?int $maxApplications): void
773  {
774  $this->maxApplications = $maxApplications;
775  }
776 
781  {
782  $this->maxApplicationsPerCustomer = $maxApplicationsPerCustomer;
783  }
784 
788  public function setCustom(?CustomFields $custom): void
789  {
790  $this->custom = $custom;
791  }
792 
796  public function setGroups(?array $groups): void
797  {
798  $this->groups = $groups;
799  }
800 
804  public function setValidFrom(?DateTimeImmutable $validFrom): void
805  {
806  $this->validFrom = $validFrom;
807  }
808 
812  public function setValidUntil(?DateTimeImmutable $validUntil): void
813  {
814  $this->validUntil = $validUntil;
815  }
816 
820  public function setApplicationVersion(?int $applicationVersion): void
821  {
822  $this->applicationVersion = $applicationVersion;
823  }
824 
825 
826  #[\ReturnTypeWillChange]
827  public function jsonSerialize()
828  {
829  $data = $this->toArray();
830  if (isset($data[DiscountCode::FIELD_CREATED_AT]) && $data[DiscountCode::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
831  $data[DiscountCode::FIELD_CREATED_AT] = $data[DiscountCode::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
832  }
833 
834  if (isset($data[DiscountCode::FIELD_LAST_MODIFIED_AT]) && $data[DiscountCode::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
835  $data[DiscountCode::FIELD_LAST_MODIFIED_AT] = $data[DiscountCode::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
836  }
837 
838  if (isset($data[DiscountCode::FIELD_VALID_FROM]) && $data[DiscountCode::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
839  $data[DiscountCode::FIELD_VALID_FROM] = $data[DiscountCode::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
840  }
841 
842  if (isset($data[DiscountCode::FIELD_VALID_UNTIL]) && $data[DiscountCode::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
843  $data[DiscountCode::FIELD_VALID_UNTIL] = $data[DiscountCode::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
844  }
845  return (object) $data;
846  }
847 }
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)
static of($data=null)
Definition: MapperMap.php:45