commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
CartDiscountModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
27 use DateTimeImmutable;
28 use stdClass;
29 
33 final class CartDiscountModel extends JsonObjectModel implements CartDiscount
34 {
39  protected $id;
40 
45  protected $version;
46 
51  protected $createdAt;
52 
57  protected $lastModifiedAt;
58 
63  protected $lastModifiedBy;
64 
69  protected $createdBy;
70 
75  protected $name;
76 
81  protected $key;
82 
87  protected $description;
88 
93  protected $value;
94 
99  protected $cartPredicate;
100 
105  protected $target;
106 
111  protected $sortOrder;
112 
117  protected $stores;
118 
123  protected $isActive;
124 
129  protected $validFrom;
130 
135  protected $validUntil;
136 
142 
147  protected $references;
148 
153  protected $stackingMode;
154 
159  protected $custom;
160 
161 
165  public function __construct(
166  ?string $id = null,
167  ?int $version = null,
168  ?DateTimeImmutable $createdAt = null,
169  ?DateTimeImmutable $lastModifiedAt = null,
171  ?CreatedBy $createdBy = null,
172  ?LocalizedString $name = null,
173  ?string $key = null,
175  ?CartDiscountValue $value = null,
176  ?string $cartPredicate = null,
177  ?CartDiscountTarget $target = null,
178  ?string $sortOrder = null,
180  ?bool $isActive = null,
181  ?DateTimeImmutable $validFrom = null,
182  ?DateTimeImmutable $validUntil = null,
183  ?bool $requiresDiscountCode = null,
185  ?string $stackingMode = null,
186  ?CustomFields $custom = null
187  ) {
188  $this->id = $id;
189  $this->version = $version;
190  $this->createdAt = $createdAt;
191  $this->lastModifiedAt = $lastModifiedAt;
192  $this->lastModifiedBy = $lastModifiedBy;
193  $this->createdBy = $createdBy;
194  $this->name = $name;
195  $this->key = $key;
196  $this->description = $description;
197  $this->value = $value;
198  $this->cartPredicate = $cartPredicate;
199  $this->target = $target;
200  $this->sortOrder = $sortOrder;
201  $this->stores = $stores;
202  $this->isActive = $isActive;
203  $this->validFrom = $validFrom;
204  $this->validUntil = $validUntil;
205  $this->requiresDiscountCode = $requiresDiscountCode;
206  $this->references = $references;
207  $this->stackingMode = $stackingMode;
208  $this->custom = $custom;
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 getLastModifiedBy()
306  {
307  if (is_null($this->lastModifiedBy)) {
309  $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
310  if (is_null($data)) {
311  return null;
312  }
313 
314  $this->lastModifiedBy = LastModifiedByModel::of($data);
315  }
316 
317  return $this->lastModifiedBy;
318  }
319 
326  public function getCreatedBy()
327  {
328  if (is_null($this->createdBy)) {
330  $data = $this->raw(self::FIELD_CREATED_BY);
331  if (is_null($data)) {
332  return null;
333  }
334 
335  $this->createdBy = CreatedByModel::of($data);
336  }
337 
338  return $this->createdBy;
339  }
340 
347  public function getName()
348  {
349  if (is_null($this->name)) {
351  $data = $this->raw(self::FIELD_NAME);
352  if (is_null($data)) {
353  return null;
354  }
355 
356  $this->name = LocalizedStringModel::of($data);
357  }
358 
359  return $this->name;
360  }
361 
368  public function getKey()
369  {
370  if (is_null($this->key)) {
372  $data = $this->raw(self::FIELD_KEY);
373  if (is_null($data)) {
374  return null;
375  }
376  $this->key = (string) $data;
377  }
378 
379  return $this->key;
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 getValue()
410  {
411  if (is_null($this->value)) {
413  $data = $this->raw(self::FIELD_VALUE);
414  if (is_null($data)) {
415  return null;
416  }
418  $this->value = $className::of($data);
419  }
420 
421  return $this->value;
422  }
423 
430  public function getCartPredicate()
431  {
432  if (is_null($this->cartPredicate)) {
434  $data = $this->raw(self::FIELD_CART_PREDICATE);
435  if (is_null($data)) {
436  return null;
437  }
438  $this->cartPredicate = (string) $data;
439  }
440 
441  return $this->cartPredicate;
442  }
443 
451  public function getTarget()
452  {
453  if (is_null($this->target)) {
455  $data = $this->raw(self::FIELD_TARGET);
456  if (is_null($data)) {
457  return null;
458  }
460  $this->target = $className::of($data);
461  }
462 
463  return $this->target;
464  }
465 
475  public function getSortOrder()
476  {
477  if (is_null($this->sortOrder)) {
479  $data = $this->raw(self::FIELD_SORT_ORDER);
480  if (is_null($data)) {
481  return null;
482  }
483  $this->sortOrder = (string) $data;
484  }
485 
486  return $this->sortOrder;
487  }
488 
498  public function getStores()
499  {
500  if (is_null($this->stores)) {
502  $data = $this->raw(self::FIELD_STORES);
503  if (is_null($data)) {
504  return null;
505  }
506  $this->stores = StoreKeyReferenceCollection::fromArray($data);
507  }
508 
509  return $this->stores;
510  }
511 
518  public function getIsActive()
519  {
520  if (is_null($this->isActive)) {
522  $data = $this->raw(self::FIELD_IS_ACTIVE);
523  if (is_null($data)) {
524  return null;
525  }
526  $this->isActive = (bool) $data;
527  }
528 
529  return $this->isActive;
530  }
531 
538  public function getValidFrom()
539  {
540  if (is_null($this->validFrom)) {
542  $data = $this->raw(self::FIELD_VALID_FROM);
543  if (is_null($data)) {
544  return null;
545  }
546  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
547  if (false === $data) {
548  return null;
549  }
550  $this->validFrom = $data;
551  }
552 
553  return $this->validFrom;
554  }
555 
562  public function getValidUntil()
563  {
564  if (is_null($this->validUntil)) {
566  $data = $this->raw(self::FIELD_VALID_UNTIL);
567  if (is_null($data)) {
568  return null;
569  }
570  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
571  if (false === $data) {
572  return null;
573  }
574  $this->validUntil = $data;
575  }
576 
577  return $this->validUntil;
578  }
579 
586  public function getRequiresDiscountCode()
587  {
588  if (is_null($this->requiresDiscountCode)) {
590  $data = $this->raw(self::FIELD_REQUIRES_DISCOUNT_CODE);
591  if (is_null($data)) {
592  return null;
593  }
594  $this->requiresDiscountCode = (bool) $data;
595  }
596 
598  }
599 
607  public function getReferences()
608  {
609  if (is_null($this->references)) {
611  $data = $this->raw(self::FIELD_REFERENCES);
612  if (is_null($data)) {
613  return null;
614  }
615  $this->references = ReferenceCollection::fromArray($data);
616  }
617 
618  return $this->references;
619  }
620 
627  public function getStackingMode()
628  {
629  if (is_null($this->stackingMode)) {
631  $data = $this->raw(self::FIELD_STACKING_MODE);
632  if (is_null($data)) {
633  return null;
634  }
635  $this->stackingMode = (string) $data;
636  }
637 
638  return $this->stackingMode;
639  }
640 
647  public function getCustom()
648  {
649  if (is_null($this->custom)) {
651  $data = $this->raw(self::FIELD_CUSTOM);
652  if (is_null($data)) {
653  return null;
654  }
655 
656  $this->custom = CustomFieldsModel::of($data);
657  }
658 
659  return $this->custom;
660  }
661 
662 
666  public function setId(?string $id): void
667  {
668  $this->id = $id;
669  }
670 
674  public function setVersion(?int $version): void
675  {
676  $this->version = $version;
677  }
678 
682  public function setCreatedAt(?DateTimeImmutable $createdAt): void
683  {
684  $this->createdAt = $createdAt;
685  }
686 
690  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
691  {
692  $this->lastModifiedAt = $lastModifiedAt;
693  }
694 
699  {
700  $this->lastModifiedBy = $lastModifiedBy;
701  }
702 
706  public function setCreatedBy(?CreatedBy $createdBy): void
707  {
708  $this->createdBy = $createdBy;
709  }
710 
714  public function setName(?LocalizedString $name): void
715  {
716  $this->name = $name;
717  }
718 
722  public function setKey(?string $key): void
723  {
724  $this->key = $key;
725  }
726 
731  {
732  $this->description = $description;
733  }
734 
738  public function setValue(?CartDiscountValue $value): void
739  {
740  $this->value = $value;
741  }
742 
746  public function setCartPredicate(?string $cartPredicate): void
747  {
748  $this->cartPredicate = $cartPredicate;
749  }
750 
754  public function setTarget(?CartDiscountTarget $target): void
755  {
756  $this->target = $target;
757  }
758 
762  public function setSortOrder(?string $sortOrder): void
763  {
764  $this->sortOrder = $sortOrder;
765  }
766 
771  {
772  $this->stores = $stores;
773  }
774 
778  public function setIsActive(?bool $isActive): void
779  {
780  $this->isActive = $isActive;
781  }
782 
786  public function setValidFrom(?DateTimeImmutable $validFrom): void
787  {
788  $this->validFrom = $validFrom;
789  }
790 
794  public function setValidUntil(?DateTimeImmutable $validUntil): void
795  {
796  $this->validUntil = $validUntil;
797  }
798 
802  public function setRequiresDiscountCode(?bool $requiresDiscountCode): void
803  {
804  $this->requiresDiscountCode = $requiresDiscountCode;
805  }
806 
811  {
812  $this->references = $references;
813  }
814 
818  public function setStackingMode(?string $stackingMode): void
819  {
820  $this->stackingMode = $stackingMode;
821  }
822 
826  public function setCustom(?CustomFields $custom): void
827  {
828  $this->custom = $custom;
829  }
830 
831 
832  #[\ReturnTypeWillChange]
833  public function jsonSerialize()
834  {
835  $data = $this->toArray();
836  if (isset($data[CartDiscount::FIELD_CREATED_AT]) && $data[CartDiscount::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
837  $data[CartDiscount::FIELD_CREATED_AT] = $data[CartDiscount::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
838  }
839 
840  if (isset($data[CartDiscount::FIELD_LAST_MODIFIED_AT]) && $data[CartDiscount::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
841  $data[CartDiscount::FIELD_LAST_MODIFIED_AT] = $data[CartDiscount::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
842  }
843 
844  if (isset($data[CartDiscount::FIELD_VALID_FROM]) && $data[CartDiscount::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
845  $data[CartDiscount::FIELD_VALID_FROM] = $data[CartDiscount::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
846  }
847 
848  if (isset($data[CartDiscount::FIELD_VALID_UNTIL]) && $data[CartDiscount::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
849  $data[CartDiscount::FIELD_VALID_UNTIL] = $data[CartDiscount::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
850  }
851  return (object) $data;
852  }
853 }
__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)
static of($data=null)
Definition: MapperMap.php:45