commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ProductDiscountModel.php
1<?php
2
3declare(strict_types=1);
10
24use DateTimeImmutable;
25use stdClass;
26
31{
36 protected $id;
37
42 protected $version;
43
48 protected $createdAt;
49
54 protected $lastModifiedAt;
55
60 protected $lastModifiedBy;
61
66 protected $createdBy;
67
72 protected $name;
73
78 protected $key;
79
84 protected $description;
85
90 protected $value;
91
96 protected $predicate;
97
102 protected $sortOrder;
103
108 protected $isActive;
109
114 protected $references;
115
120 protected $validFrom;
121
126 protected $validUntil;
127
128
132 public function __construct(
133 ?string $id = null,
134 ?int $version = null,
135 ?DateTimeImmutable $createdAt = null,
136 ?DateTimeImmutable $lastModifiedAt = null,
138 ?CreatedBy $createdBy = null,
139 ?LocalizedString $name = null,
140 ?string $key = null,
143 ?string $predicate = null,
144 ?string $sortOrder = null,
145 ?bool $isActive = null,
147 ?DateTimeImmutable $validFrom = null,
148 ?DateTimeImmutable $validUntil = null
149 ) {
150 $this->id = $id;
151 $this->version = $version;
152 $this->createdAt = $createdAt;
153 $this->lastModifiedAt = $lastModifiedAt;
154 $this->lastModifiedBy = $lastModifiedBy;
155 $this->createdBy = $createdBy;
156 $this->name = $name;
157 $this->key = $key;
158 $this->description = $description;
159 $this->value = $value;
160 $this->predicate = $predicate;
161 $this->sortOrder = $sortOrder;
162 $this->isActive = $isActive;
163 $this->references = $references;
164 $this->validFrom = $validFrom;
165 $this->validUntil = $validUntil;
166 }
167
174 public function getId()
175 {
176 if (is_null($this->id)) {
178 $data = $this->raw(self::FIELD_ID);
179 if (is_null($data)) {
180 return null;
181 }
182 $this->id = (string) $data;
183 }
184
185 return $this->id;
186 }
187
194 public function getVersion()
195 {
196 if (is_null($this->version)) {
198 $data = $this->raw(self::FIELD_VERSION);
199 if (is_null($data)) {
200 return null;
201 }
202 $this->version = (int) $data;
203 }
204
205 return $this->version;
206 }
207
214 public function getCreatedAt()
215 {
216 if (is_null($this->createdAt)) {
218 $data = $this->raw(self::FIELD_CREATED_AT);
219 if (is_null($data)) {
220 return null;
221 }
222 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
223 if (false === $data) {
224 return null;
225 }
226 $this->createdAt = $data;
227 }
228
229 return $this->createdAt;
230 }
231
238 public function getLastModifiedAt()
239 {
240 if (is_null($this->lastModifiedAt)) {
242 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
243 if (is_null($data)) {
244 return null;
245 }
246 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
247 if (false === $data) {
248 return null;
249 }
250 $this->lastModifiedAt = $data;
251 }
252
254 }
255
262 public function getLastModifiedBy()
263 {
264 if (is_null($this->lastModifiedBy)) {
266 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
267 if (is_null($data)) {
268 return null;
269 }
270
271 $this->lastModifiedBy = LastModifiedByModel::of($data);
272 }
273
275 }
276
283 public function getCreatedBy()
284 {
285 if (is_null($this->createdBy)) {
287 $data = $this->raw(self::FIELD_CREATED_BY);
288 if (is_null($data)) {
289 return null;
290 }
291
292 $this->createdBy = CreatedByModel::of($data);
293 }
294
295 return $this->createdBy;
296 }
297
304 public function getName()
305 {
306 if (is_null($this->name)) {
308 $data = $this->raw(self::FIELD_NAME);
309 if (is_null($data)) {
310 return null;
311 }
312
313 $this->name = LocalizedStringModel::of($data);
314 }
315
316 return $this->name;
317 }
318
325 public function getKey()
326 {
327 if (is_null($this->key)) {
329 $data = $this->raw(self::FIELD_KEY);
330 if (is_null($data)) {
331 return null;
332 }
333 $this->key = (string) $data;
334 }
335
336 return $this->key;
337 }
338
345 public function getDescription()
346 {
347 if (is_null($this->description)) {
349 $data = $this->raw(self::FIELD_DESCRIPTION);
350 if (is_null($data)) {
351 return null;
352 }
353
354 $this->description = LocalizedStringModel::of($data);
355 }
356
357 return $this->description;
358 }
359
366 public function getValue()
367 {
368 if (is_null($this->value)) {
370 $data = $this->raw(self::FIELD_VALUE);
371 if (is_null($data)) {
372 return null;
373 }
375 $this->value = $className::of($data);
376 }
377
378 return $this->value;
379 }
380
387 public function getPredicate()
388 {
389 if (is_null($this->predicate)) {
391 $data = $this->raw(self::FIELD_PREDICATE);
392 if (is_null($data)) {
393 return null;
394 }
395 $this->predicate = (string) $data;
396 }
397
398 return $this->predicate;
399 }
400
408 public function getSortOrder()
409 {
410 if (is_null($this->sortOrder)) {
412 $data = $this->raw(self::FIELD_SORT_ORDER);
413 if (is_null($data)) {
414 return null;
415 }
416 $this->sortOrder = (string) $data;
417 }
418
419 return $this->sortOrder;
420 }
421
428 public function getIsActive()
429 {
430 if (is_null($this->isActive)) {
432 $data = $this->raw(self::FIELD_IS_ACTIVE);
433 if (is_null($data)) {
434 return null;
435 }
436 $this->isActive = (bool) $data;
437 }
438
439 return $this->isActive;
440 }
441
448 public function getReferences()
449 {
450 if (is_null($this->references)) {
452 $data = $this->raw(self::FIELD_REFERENCES);
453 if (is_null($data)) {
454 return null;
455 }
456 $this->references = ReferenceCollection::fromArray($data);
457 }
458
459 return $this->references;
460 }
461
469 public function getValidFrom()
470 {
471 if (is_null($this->validFrom)) {
473 $data = $this->raw(self::FIELD_VALID_FROM);
474 if (is_null($data)) {
475 return null;
476 }
477 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
478 if (false === $data) {
479 return null;
480 }
481 $this->validFrom = $data;
482 }
483
484 return $this->validFrom;
485 }
486
494 public function getValidUntil()
495 {
496 if (is_null($this->validUntil)) {
498 $data = $this->raw(self::FIELD_VALID_UNTIL);
499 if (is_null($data)) {
500 return null;
501 }
502 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
503 if (false === $data) {
504 return null;
505 }
506 $this->validUntil = $data;
507 }
508
509 return $this->validUntil;
510 }
511
512
516 public function setId(?string $id): void
517 {
518 $this->id = $id;
519 }
520
524 public function setVersion(?int $version): void
525 {
526 $this->version = $version;
527 }
528
532 public function setCreatedAt(?DateTimeImmutable $createdAt): void
533 {
534 $this->createdAt = $createdAt;
535 }
536
540 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
541 {
542 $this->lastModifiedAt = $lastModifiedAt;
543 }
544
549 {
550 $this->lastModifiedBy = $lastModifiedBy;
551 }
552
556 public function setCreatedBy(?CreatedBy $createdBy): void
557 {
558 $this->createdBy = $createdBy;
559 }
560
564 public function setName(?LocalizedString $name): void
565 {
566 $this->name = $name;
567 }
568
572 public function setKey(?string $key): void
573 {
574 $this->key = $key;
575 }
576
581 {
582 $this->description = $description;
583 }
584
588 public function setValue(?ProductDiscountValue $value): void
589 {
590 $this->value = $value;
591 }
592
596 public function setPredicate(?string $predicate): void
597 {
598 $this->predicate = $predicate;
599 }
600
604 public function setSortOrder(?string $sortOrder): void
605 {
606 $this->sortOrder = $sortOrder;
607 }
608
612 public function setIsActive(?bool $isActive): void
613 {
614 $this->isActive = $isActive;
615 }
616
621 {
622 $this->references = $references;
623 }
624
628 public function setValidFrom(?DateTimeImmutable $validFrom): void
629 {
630 $this->validFrom = $validFrom;
631 }
632
636 public function setValidUntil(?DateTimeImmutable $validUntil): void
637 {
638 $this->validUntil = $validUntil;
639 }
640
641
642 #[\ReturnTypeWillChange]
643 public function jsonSerialize()
644 {
645 $data = $this->toArray();
646 if (isset($data[ProductDiscount::FIELD_CREATED_AT]) && $data[ProductDiscount::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
647 $data[ProductDiscount::FIELD_CREATED_AT] = $data[ProductDiscount::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
648 }
649
650 if (isset($data[ProductDiscount::FIELD_LAST_MODIFIED_AT]) && $data[ProductDiscount::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
651 $data[ProductDiscount::FIELD_LAST_MODIFIED_AT] = $data[ProductDiscount::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
652 }
653
654 if (isset($data[ProductDiscount::FIELD_VALID_FROM]) && $data[ProductDiscount::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
655 $data[ProductDiscount::FIELD_VALID_FROM] = $data[ProductDiscount::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
656 }
657
658 if (isset($data[ProductDiscount::FIELD_VALID_UNTIL]) && $data[ProductDiscount::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
659 $data[ProductDiscount::FIELD_VALID_UNTIL] = $data[ProductDiscount::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
660 }
661 return (object) $data;
662 }
663}
__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, ?ProductDiscountValue $value=null, ?string $predicate=null, ?string $sortOrder=null, ?bool $isActive=null, ?ReferenceCollection $references=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null)