commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
CategoryModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
26 use DateTimeImmutable;
27 use stdClass;
28 
32 final class CategoryModel extends JsonObjectModel implements Category
33 {
38  protected $id;
39 
44  protected $version;
45 
50  protected $createdAt;
51 
56  protected $lastModifiedAt;
57 
62  protected $lastModifiedBy;
63 
68  protected $createdBy;
69 
74  protected $name;
75 
80  protected $slug;
81 
86  protected $description;
87 
92  protected $ancestors;
93 
98  protected $parent;
99 
104  protected $orderHint;
105 
110  protected $externalId;
111 
116  protected $metaTitle;
117 
122  protected $metaDescription;
123 
128  protected $metaKeywords;
129 
134  protected $custom;
135 
140  protected $assets;
141 
146  protected $key;
147 
148 
152  public function __construct(
153  ?string $id = null,
154  ?int $version = null,
155  ?DateTimeImmutable $createdAt = null,
156  ?DateTimeImmutable $lastModifiedAt = null,
158  ?CreatedBy $createdBy = null,
159  ?LocalizedString $name = null,
160  ?LocalizedString $slug = null,
163  ?CategoryReference $parent = null,
164  ?string $orderHint = null,
165  ?string $externalId = null,
166  ?LocalizedString $metaTitle = null,
169  ?CustomFields $custom = null,
170  ?AssetCollection $assets = null,
171  ?string $key = null
172  ) {
173  $this->id = $id;
174  $this->version = $version;
175  $this->createdAt = $createdAt;
176  $this->lastModifiedAt = $lastModifiedAt;
177  $this->lastModifiedBy = $lastModifiedBy;
178  $this->createdBy = $createdBy;
179  $this->name = $name;
180  $this->slug = $slug;
181  $this->description = $description;
182  $this->ancestors = $ancestors;
183  $this->parent = $parent;
184  $this->orderHint = $orderHint;
185  $this->externalId = $externalId;
186  $this->metaTitle = $metaTitle;
187  $this->metaDescription = $metaDescription;
188  $this->metaKeywords = $metaKeywords;
189  $this->custom = $custom;
190  $this->assets = $assets;
191  $this->key = $key;
192  }
193 
200  public function getId()
201  {
202  if (is_null($this->id)) {
204  $data = $this->raw(self::FIELD_ID);
205  if (is_null($data)) {
206  return null;
207  }
208  $this->id = (string) $data;
209  }
210 
211  return $this->id;
212  }
213 
220  public function getVersion()
221  {
222  if (is_null($this->version)) {
224  $data = $this->raw(self::FIELD_VERSION);
225  if (is_null($data)) {
226  return null;
227  }
228  $this->version = (int) $data;
229  }
230 
231  return $this->version;
232  }
233 
240  public function getCreatedAt()
241  {
242  if (is_null($this->createdAt)) {
244  $data = $this->raw(self::FIELD_CREATED_AT);
245  if (is_null($data)) {
246  return null;
247  }
248  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
249  if (false === $data) {
250  return null;
251  }
252  $this->createdAt = $data;
253  }
254 
255  return $this->createdAt;
256  }
257 
264  public function getLastModifiedAt()
265  {
266  if (is_null($this->lastModifiedAt)) {
268  $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
269  if (is_null($data)) {
270  return null;
271  }
272  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
273  if (false === $data) {
274  return null;
275  }
276  $this->lastModifiedAt = $data;
277  }
278 
279  return $this->lastModifiedAt;
280  }
281 
288  public function getLastModifiedBy()
289  {
290  if (is_null($this->lastModifiedBy)) {
292  $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
293  if (is_null($data)) {
294  return null;
295  }
296 
297  $this->lastModifiedBy = LastModifiedByModel::of($data);
298  }
299 
300  return $this->lastModifiedBy;
301  }
302 
309  public function getCreatedBy()
310  {
311  if (is_null($this->createdBy)) {
313  $data = $this->raw(self::FIELD_CREATED_BY);
314  if (is_null($data)) {
315  return null;
316  }
317 
318  $this->createdBy = CreatedByModel::of($data);
319  }
320 
321  return $this->createdBy;
322  }
323 
330  public function getName()
331  {
332  if (is_null($this->name)) {
334  $data = $this->raw(self::FIELD_NAME);
335  if (is_null($data)) {
336  return null;
337  }
338 
339  $this->name = LocalizedStringModel::of($data);
340  }
341 
342  return $this->name;
343  }
344 
354  public function getSlug()
355  {
356  if (is_null($this->slug)) {
358  $data = $this->raw(self::FIELD_SLUG);
359  if (is_null($data)) {
360  return null;
361  }
362 
363  $this->slug = LocalizedStringModel::of($data);
364  }
365 
366  return $this->slug;
367  }
368 
375  public function getDescription()
376  {
377  if (is_null($this->description)) {
379  $data = $this->raw(self::FIELD_DESCRIPTION);
380  if (is_null($data)) {
381  return null;
382  }
383 
384  $this->description = LocalizedStringModel::of($data);
385  }
386 
387  return $this->description;
388  }
389 
396  public function getAncestors()
397  {
398  if (is_null($this->ancestors)) {
400  $data = $this->raw(self::FIELD_ANCESTORS);
401  if (is_null($data)) {
402  return null;
403  }
404  $this->ancestors = CategoryReferenceCollection::fromArray($data);
405  }
406 
407  return $this->ancestors;
408  }
409 
416  public function getParent()
417  {
418  if (is_null($this->parent)) {
420  $data = $this->raw(self::FIELD_PARENT);
421  if (is_null($data)) {
422  return null;
423  }
424 
425  $this->parent = CategoryReferenceModel::of($data);
426  }
427 
428  return $this->parent;
429  }
430 
437  public function getOrderHint()
438  {
439  if (is_null($this->orderHint)) {
441  $data = $this->raw(self::FIELD_ORDER_HINT);
442  if (is_null($data)) {
443  return null;
444  }
445  $this->orderHint = (string) $data;
446  }
447 
448  return $this->orderHint;
449  }
450 
457  public function getExternalId()
458  {
459  if (is_null($this->externalId)) {
461  $data = $this->raw(self::FIELD_EXTERNAL_ID);
462  if (is_null($data)) {
463  return null;
464  }
465  $this->externalId = (string) $data;
466  }
467 
468  return $this->externalId;
469  }
470 
477  public function getMetaTitle()
478  {
479  if (is_null($this->metaTitle)) {
481  $data = $this->raw(self::FIELD_META_TITLE);
482  if (is_null($data)) {
483  return null;
484  }
485 
486  $this->metaTitle = LocalizedStringModel::of($data);
487  }
488 
489  return $this->metaTitle;
490  }
491 
498  public function getMetaDescription()
499  {
500  if (is_null($this->metaDescription)) {
502  $data = $this->raw(self::FIELD_META_DESCRIPTION);
503  if (is_null($data)) {
504  return null;
505  }
506 
507  $this->metaDescription = LocalizedStringModel::of($data);
508  }
509 
510  return $this->metaDescription;
511  }
512 
519  public function getMetaKeywords()
520  {
521  if (is_null($this->metaKeywords)) {
523  $data = $this->raw(self::FIELD_META_KEYWORDS);
524  if (is_null($data)) {
525  return null;
526  }
527 
528  $this->metaKeywords = LocalizedStringModel::of($data);
529  }
530 
531  return $this->metaKeywords;
532  }
533 
540  public function getCustom()
541  {
542  if (is_null($this->custom)) {
544  $data = $this->raw(self::FIELD_CUSTOM);
545  if (is_null($data)) {
546  return null;
547  }
548 
549  $this->custom = CustomFieldsModel::of($data);
550  }
551 
552  return $this->custom;
553  }
554 
561  public function getAssets()
562  {
563  if (is_null($this->assets)) {
565  $data = $this->raw(self::FIELD_ASSETS);
566  if (is_null($data)) {
567  return null;
568  }
569  $this->assets = AssetCollection::fromArray($data);
570  }
571 
572  return $this->assets;
573  }
574 
581  public function getKey()
582  {
583  if (is_null($this->key)) {
585  $data = $this->raw(self::FIELD_KEY);
586  if (is_null($data)) {
587  return null;
588  }
589  $this->key = (string) $data;
590  }
591 
592  return $this->key;
593  }
594 
595 
599  public function setId(?string $id): void
600  {
601  $this->id = $id;
602  }
603 
607  public function setVersion(?int $version): void
608  {
609  $this->version = $version;
610  }
611 
615  public function setCreatedAt(?DateTimeImmutable $createdAt): void
616  {
617  $this->createdAt = $createdAt;
618  }
619 
623  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
624  {
625  $this->lastModifiedAt = $lastModifiedAt;
626  }
627 
632  {
633  $this->lastModifiedBy = $lastModifiedBy;
634  }
635 
639  public function setCreatedBy(?CreatedBy $createdBy): void
640  {
641  $this->createdBy = $createdBy;
642  }
643 
647  public function setName(?LocalizedString $name): void
648  {
649  $this->name = $name;
650  }
651 
655  public function setSlug(?LocalizedString $slug): void
656  {
657  $this->slug = $slug;
658  }
659 
664  {
665  $this->description = $description;
666  }
667 
672  {
673  $this->ancestors = $ancestors;
674  }
675 
679  public function setParent(?CategoryReference $parent): void
680  {
681  $this->parent = $parent;
682  }
683 
687  public function setOrderHint(?string $orderHint): void
688  {
689  $this->orderHint = $orderHint;
690  }
691 
695  public function setExternalId(?string $externalId): void
696  {
697  $this->externalId = $externalId;
698  }
699 
703  public function setMetaTitle(?LocalizedString $metaTitle): void
704  {
705  $this->metaTitle = $metaTitle;
706  }
707 
712  {
713  $this->metaDescription = $metaDescription;
714  }
715 
720  {
721  $this->metaKeywords = $metaKeywords;
722  }
723 
727  public function setCustom(?CustomFields $custom): void
728  {
729  $this->custom = $custom;
730  }
731 
735  public function setAssets(?AssetCollection $assets): void
736  {
737  $this->assets = $assets;
738  }
739 
743  public function setKey(?string $key): void
744  {
745  $this->key = $key;
746  }
747 
748 
749  #[\ReturnTypeWillChange]
750  public function jsonSerialize()
751  {
752  $data = $this->toArray();
753  if (isset($data[Category::FIELD_CREATED_AT]) && $data[Category::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
754  $data[Category::FIELD_CREATED_AT] = $data[Category::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
755  }
756 
757  if (isset($data[Category::FIELD_LAST_MODIFIED_AT]) && $data[Category::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
758  $data[Category::FIELD_LAST_MODIFIED_AT] = $data[Category::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
759  }
760  return (object) $data;
761  }
762 }
setCreatedAt(?DateTimeImmutable $createdAt)
setMetaDescription(?LocalizedString $metaDescription)
setDescription(?LocalizedString $description)
setMetaKeywords(?LocalizedString $metaKeywords)
setAncestors(?CategoryReferenceCollection $ancestors)
setLastModifiedBy(?LastModifiedBy $lastModifiedBy)
setLastModifiedAt(?DateTimeImmutable $lastModifiedAt)
__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)
static of($data=null)
Definition: MapperMap.php:45