commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CategoryModel.php
1<?php
2
3declare(strict_types=1);
10
27use DateTimeImmutable;
28use stdClass;
29
33final class CategoryModel extends JsonObjectModel implements Category
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 $slug;
82
87 protected $description;
88
93 protected $ancestors;
94
99 protected $parent;
100
105 protected $orderHint;
106
111 protected $externalId;
112
117 protected $metaTitle;
118
124
129 protected $metaKeywords;
130
135 protected $custom;
136
141 protected $assets;
142
147 protected $key;
148
153 protected $stores;
154
155
159 public function __construct(
160 ?string $id = null,
161 ?int $version = null,
162 ?DateTimeImmutable $createdAt = null,
163 ?DateTimeImmutable $lastModifiedAt = null,
165 ?CreatedBy $createdBy = null,
166 ?LocalizedString $name = null,
167 ?LocalizedString $slug = null,
171 ?string $orderHint = null,
172 ?string $externalId = null,
176 ?CustomFields $custom = null,
177 ?AssetCollection $assets = null,
178 ?string $key = null,
180 ) {
181 $this->id = $id;
182 $this->version = $version;
183 $this->createdAt = $createdAt;
184 $this->lastModifiedAt = $lastModifiedAt;
185 $this->lastModifiedBy = $lastModifiedBy;
186 $this->createdBy = $createdBy;
187 $this->name = $name;
188 $this->slug = $slug;
189 $this->description = $description;
190 $this->ancestors = $ancestors;
191 $this->parent = $parent;
192 $this->orderHint = $orderHint;
193 $this->externalId = $externalId;
194 $this->metaTitle = $metaTitle;
195 $this->metaDescription = $metaDescription;
196 $this->metaKeywords = $metaKeywords;
197 $this->custom = $custom;
198 $this->assets = $assets;
199 $this->key = $key;
200 $this->stores = $stores;
201 }
202
209 public function getId()
210 {
211 if (is_null($this->id)) {
213 $data = $this->raw(self::FIELD_ID);
214 if (is_null($data)) {
215 return null;
216 }
217 $this->id = (string) $data;
218 }
219
220 return $this->id;
221 }
222
229 public function getVersion()
230 {
231 if (is_null($this->version)) {
233 $data = $this->raw(self::FIELD_VERSION);
234 if (is_null($data)) {
235 return null;
236 }
237 $this->version = (int) $data;
238 }
239
240 return $this->version;
241 }
242
249 public function getCreatedAt()
250 {
251 if (is_null($this->createdAt)) {
253 $data = $this->raw(self::FIELD_CREATED_AT);
254 if (is_null($data)) {
255 return null;
256 }
257 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
258 if (false === $data) {
259 return null;
260 }
261 $this->createdAt = $data;
262 }
263
264 return $this->createdAt;
265 }
266
273 public function getLastModifiedAt()
274 {
275 if (is_null($this->lastModifiedAt)) {
277 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
278 if (is_null($data)) {
279 return null;
280 }
281 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
282 if (false === $data) {
283 return null;
284 }
285 $this->lastModifiedAt = $data;
286 }
287
289 }
290
297 public function getLastModifiedBy()
298 {
299 if (is_null($this->lastModifiedBy)) {
301 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
302 if (is_null($data)) {
303 return null;
304 }
305
306 $this->lastModifiedBy = LastModifiedByModel::of($data);
307 }
308
310 }
311
318 public function getCreatedBy()
319 {
320 if (is_null($this->createdBy)) {
322 $data = $this->raw(self::FIELD_CREATED_BY);
323 if (is_null($data)) {
324 return null;
325 }
326
327 $this->createdBy = CreatedByModel::of($data);
328 }
329
330 return $this->createdBy;
331 }
332
339 public function getName()
340 {
341 if (is_null($this->name)) {
343 $data = $this->raw(self::FIELD_NAME);
344 if (is_null($data)) {
345 return null;
346 }
347
348 $this->name = LocalizedStringModel::of($data);
349 }
350
351 return $this->name;
352 }
353
363 public function getSlug()
364 {
365 if (is_null($this->slug)) {
367 $data = $this->raw(self::FIELD_SLUG);
368 if (is_null($data)) {
369 return null;
370 }
371
372 $this->slug = LocalizedStringModel::of($data);
373 }
374
375 return $this->slug;
376 }
377
384 public function getDescription()
385 {
386 if (is_null($this->description)) {
388 $data = $this->raw(self::FIELD_DESCRIPTION);
389 if (is_null($data)) {
390 return null;
391 }
392
393 $this->description = LocalizedStringModel::of($data);
394 }
395
396 return $this->description;
397 }
398
405 public function getAncestors()
406 {
407 if (is_null($this->ancestors)) {
409 $data = $this->raw(self::FIELD_ANCESTORS);
410 if (is_null($data)) {
411 return null;
412 }
413 $this->ancestors = CategoryReferenceCollection::fromArray($data);
414 }
415
416 return $this->ancestors;
417 }
418
425 public function getParent()
426 {
427 if (is_null($this->parent)) {
429 $data = $this->raw(self::FIELD_PARENT);
430 if (is_null($data)) {
431 return null;
432 }
433
434 $this->parent = CategoryReferenceModel::of($data);
435 }
436
437 return $this->parent;
438 }
439
446 public function getOrderHint()
447 {
448 if (is_null($this->orderHint)) {
450 $data = $this->raw(self::FIELD_ORDER_HINT);
451 if (is_null($data)) {
452 return null;
453 }
454 $this->orderHint = (string) $data;
455 }
456
457 return $this->orderHint;
458 }
459
466 public function getExternalId()
467 {
468 if (is_null($this->externalId)) {
470 $data = $this->raw(self::FIELD_EXTERNAL_ID);
471 if (is_null($data)) {
472 return null;
473 }
474 $this->externalId = (string) $data;
475 }
476
477 return $this->externalId;
478 }
479
486 public function getMetaTitle()
487 {
488 if (is_null($this->metaTitle)) {
490 $data = $this->raw(self::FIELD_META_TITLE);
491 if (is_null($data)) {
492 return null;
493 }
494
495 $this->metaTitle = LocalizedStringModel::of($data);
496 }
497
498 return $this->metaTitle;
499 }
500
507 public function getMetaDescription()
508 {
509 if (is_null($this->metaDescription)) {
511 $data = $this->raw(self::FIELD_META_DESCRIPTION);
512 if (is_null($data)) {
513 return null;
514 }
515
516 $this->metaDescription = LocalizedStringModel::of($data);
517 }
518
520 }
521
528 public function getMetaKeywords()
529 {
530 if (is_null($this->metaKeywords)) {
532 $data = $this->raw(self::FIELD_META_KEYWORDS);
533 if (is_null($data)) {
534 return null;
535 }
536
537 $this->metaKeywords = LocalizedStringModel::of($data);
538 }
539
540 return $this->metaKeywords;
541 }
542
549 public function getCustom()
550 {
551 if (is_null($this->custom)) {
553 $data = $this->raw(self::FIELD_CUSTOM);
554 if (is_null($data)) {
555 return null;
556 }
557
558 $this->custom = CustomFieldsModel::of($data);
559 }
560
561 return $this->custom;
562 }
563
570 public function getAssets()
571 {
572 if (is_null($this->assets)) {
574 $data = $this->raw(self::FIELD_ASSETS);
575 if (is_null($data)) {
576 return null;
577 }
578 $this->assets = AssetCollection::fromArray($data);
579 }
580
581 return $this->assets;
582 }
583
590 public function getKey()
591 {
592 if (is_null($this->key)) {
594 $data = $this->raw(self::FIELD_KEY);
595 if (is_null($data)) {
596 return null;
597 }
598 $this->key = (string) $data;
599 }
600
601 return $this->key;
602 }
603
612 public function getStores()
613 {
614 if (is_null($this->stores)) {
616 $data = $this->raw(self::FIELD_STORES);
617 if (is_null($data)) {
618 return null;
619 }
620 $this->stores = StoreKeyReferenceCollection::fromArray($data);
621 }
622
623 return $this->stores;
624 }
625
626
630 public function setId(?string $id): void
631 {
632 $this->id = $id;
633 }
634
638 public function setVersion(?int $version): void
639 {
640 $this->version = $version;
641 }
642
646 public function setCreatedAt(?DateTimeImmutable $createdAt): void
647 {
648 $this->createdAt = $createdAt;
649 }
650
654 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
655 {
656 $this->lastModifiedAt = $lastModifiedAt;
657 }
658
663 {
664 $this->lastModifiedBy = $lastModifiedBy;
665 }
666
670 public function setCreatedBy(?CreatedBy $createdBy): void
671 {
672 $this->createdBy = $createdBy;
673 }
674
678 public function setName(?LocalizedString $name): void
679 {
680 $this->name = $name;
681 }
682
686 public function setSlug(?LocalizedString $slug): void
687 {
688 $this->slug = $slug;
689 }
690
695 {
696 $this->description = $description;
697 }
698
703 {
704 $this->ancestors = $ancestors;
705 }
706
710 public function setParent(?CategoryReference $parent): void
711 {
712 $this->parent = $parent;
713 }
714
718 public function setOrderHint(?string $orderHint): void
719 {
720 $this->orderHint = $orderHint;
721 }
722
726 public function setExternalId(?string $externalId): void
727 {
728 $this->externalId = $externalId;
729 }
730
735 {
736 $this->metaTitle = $metaTitle;
737 }
738
743 {
744 $this->metaDescription = $metaDescription;
745 }
746
751 {
752 $this->metaKeywords = $metaKeywords;
753 }
754
758 public function setCustom(?CustomFields $custom): void
759 {
760 $this->custom = $custom;
761 }
762
766 public function setAssets(?AssetCollection $assets): void
767 {
768 $this->assets = $assets;
769 }
770
774 public function setKey(?string $key): void
775 {
776 $this->key = $key;
777 }
778
783 {
784 $this->stores = $stores;
785 }
786
787
788 #[\ReturnTypeWillChange]
789 public function jsonSerialize()
790 {
791 $data = $this->toArray();
792 if (isset($data[Category::FIELD_CREATED_AT]) && $data[Category::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
793 $data[Category::FIELD_CREATED_AT] = $data[Category::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
794 }
795
796 if (isset($data[Category::FIELD_LAST_MODIFIED_AT]) && $data[Category::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
797 $data[Category::FIELD_LAST_MODIFIED_AT] = $data[Category::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
798 }
799 return (object) $data;
800 }
801}
setCreatedAt(?DateTimeImmutable $createdAt)
setMetaDescription(?LocalizedString $metaDescription)
setDescription(?LocalizedString $description)
setMetaKeywords(?LocalizedString $metaKeywords)
setStores(?StoreKeyReferenceCollection $stores)
setAncestors(?CategoryReferenceCollection $ancestors)
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?LocalizedString $name=null, ?LocalizedString $slug=null, ?LocalizedString $description=null, ?CategoryReferenceCollection $ancestors=null, ?CategoryReference $parent=null, ?string $orderHint=null, ?string $externalId=null, ?LocalizedString $metaTitle=null, ?LocalizedString $metaDescription=null, ?LocalizedString $metaKeywords=null, ?CustomFields $custom=null, ?AssetCollection $assets=null, ?string $key=null, ?StoreKeyReferenceCollection $stores=null)
setLastModifiedBy(?LastModifiedBy $lastModifiedBy)
setLastModifiedAt(?DateTimeImmutable $lastModifiedAt)
static fromArray(array $data)