commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
ProductProjectionModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
28 use DateTimeImmutable;
29 use stdClass;
30 
35 {
40  protected $id;
41 
46  protected $version;
47 
52  protected $createdAt;
53 
58  protected $lastModifiedAt;
59 
64  protected $key;
65 
70  protected $productType;
71 
76  protected $name;
77 
82  protected $description;
83 
88  protected $slug;
89 
94  protected $categories;
95 
101 
106  protected $metaTitle;
107 
112  protected $metaDescription;
113 
118  protected $metaKeywords;
119 
124  protected $searchKeywords;
125 
130  protected $hasStagedChanges;
131 
136  protected $published;
137 
142  protected $masterVariant;
143 
148  protected $variants;
149 
154  protected $taxCategory;
155 
160  protected $state;
161 
167 
172  protected $priceMode;
173 
174 
178  public function __construct(
179  ?string $id = null,
180  ?int $version = null,
181  ?DateTimeImmutable $createdAt = null,
182  ?DateTimeImmutable $lastModifiedAt = null,
183  ?string $key = null,
185  ?LocalizedString $name = null,
187  ?LocalizedString $slug = null,
190  ?LocalizedString $metaTitle = null,
194  ?bool $hasStagedChanges = null,
195  ?bool $published = null,
199  ?StateReference $state = null,
201  ?string $priceMode = null
202  ) {
203  $this->id = $id;
204  $this->version = $version;
205  $this->createdAt = $createdAt;
206  $this->lastModifiedAt = $lastModifiedAt;
207  $this->key = $key;
208  $this->productType = $productType;
209  $this->name = $name;
210  $this->description = $description;
211  $this->slug = $slug;
212  $this->categories = $categories;
213  $this->categoryOrderHints = $categoryOrderHints;
214  $this->metaTitle = $metaTitle;
215  $this->metaDescription = $metaDescription;
216  $this->metaKeywords = $metaKeywords;
217  $this->searchKeywords = $searchKeywords;
218  $this->hasStagedChanges = $hasStagedChanges;
219  $this->published = $published;
220  $this->masterVariant = $masterVariant;
221  $this->variants = $variants;
222  $this->taxCategory = $taxCategory;
223  $this->state = $state;
224  $this->reviewRatingStatistics = $reviewRatingStatistics;
225  $this->priceMode = $priceMode;
226  }
227 
234  public function getId()
235  {
236  if (is_null($this->id)) {
238  $data = $this->raw(self::FIELD_ID);
239  if (is_null($data)) {
240  return null;
241  }
242  $this->id = (string) $data;
243  }
244 
245  return $this->id;
246  }
247 
254  public function getVersion()
255  {
256  if (is_null($this->version)) {
258  $data = $this->raw(self::FIELD_VERSION);
259  if (is_null($data)) {
260  return null;
261  }
262  $this->version = (int) $data;
263  }
264 
265  return $this->version;
266  }
267 
274  public function getCreatedAt()
275  {
276  if (is_null($this->createdAt)) {
278  $data = $this->raw(self::FIELD_CREATED_AT);
279  if (is_null($data)) {
280  return null;
281  }
282  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
283  if (false === $data) {
284  return null;
285  }
286  $this->createdAt = $data;
287  }
288 
289  return $this->createdAt;
290  }
291 
298  public function getLastModifiedAt()
299  {
300  if (is_null($this->lastModifiedAt)) {
302  $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
303  if (is_null($data)) {
304  return null;
305  }
306  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
307  if (false === $data) {
308  return null;
309  }
310  $this->lastModifiedAt = $data;
311  }
312 
313  return $this->lastModifiedAt;
314  }
315 
322  public function getKey()
323  {
324  if (is_null($this->key)) {
326  $data = $this->raw(self::FIELD_KEY);
327  if (is_null($data)) {
328  return null;
329  }
330  $this->key = (string) $data;
331  }
332 
333  return $this->key;
334  }
335 
342  public function getProductType()
343  {
344  if (is_null($this->productType)) {
346  $data = $this->raw(self::FIELD_PRODUCT_TYPE);
347  if (is_null($data)) {
348  return null;
349  }
350 
351  $this->productType = ProductTypeReferenceModel::of($data);
352  }
353 
354  return $this->productType;
355  }
356 
363  public function getName()
364  {
365  if (is_null($this->name)) {
367  $data = $this->raw(self::FIELD_NAME);
368  if (is_null($data)) {
369  return null;
370  }
371 
372  $this->name = LocalizedStringModel::of($data);
373  }
374 
375  return $this->name;
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 
408  public function getSlug()
409  {
410  if (is_null($this->slug)) {
412  $data = $this->raw(self::FIELD_SLUG);
413  if (is_null($data)) {
414  return null;
415  }
416 
417  $this->slug = LocalizedStringModel::of($data);
418  }
419 
420  return $this->slug;
421  }
422 
429  public function getCategories()
430  {
431  if (is_null($this->categories)) {
433  $data = $this->raw(self::FIELD_CATEGORIES);
434  if (is_null($data)) {
435  return null;
436  }
437  $this->categories = CategoryReferenceCollection::fromArray($data);
438  }
439 
440  return $this->categories;
441  }
442 
449  public function getCategoryOrderHints()
450  {
451  if (is_null($this->categoryOrderHints)) {
453  $data = $this->raw(self::FIELD_CATEGORY_ORDER_HINTS);
454  if (is_null($data)) {
455  return null;
456  }
457 
458  $this->categoryOrderHints = CategoryOrderHintsModel::of($data);
459  }
460 
462  }
463 
470  public function getMetaTitle()
471  {
472  if (is_null($this->metaTitle)) {
474  $data = $this->raw(self::FIELD_META_TITLE);
475  if (is_null($data)) {
476  return null;
477  }
478 
479  $this->metaTitle = LocalizedStringModel::of($data);
480  }
481 
482  return $this->metaTitle;
483  }
484 
491  public function getMetaDescription()
492  {
493  if (is_null($this->metaDescription)) {
495  $data = $this->raw(self::FIELD_META_DESCRIPTION);
496  if (is_null($data)) {
497  return null;
498  }
499 
500  $this->metaDescription = LocalizedStringModel::of($data);
501  }
502 
503  return $this->metaDescription;
504  }
505 
512  public function getMetaKeywords()
513  {
514  if (is_null($this->metaKeywords)) {
516  $data = $this->raw(self::FIELD_META_KEYWORDS);
517  if (is_null($data)) {
518  return null;
519  }
520 
521  $this->metaKeywords = LocalizedStringModel::of($data);
522  }
523 
524  return $this->metaKeywords;
525  }
526 
533  public function getSearchKeywords()
534  {
535  if (is_null($this->searchKeywords)) {
537  $data = $this->raw(self::FIELD_SEARCH_KEYWORDS);
538  if (is_null($data)) {
539  return null;
540  }
541 
542  $this->searchKeywords = SearchKeywordsModel::of($data);
543  }
544 
545  return $this->searchKeywords;
546  }
547 
554  public function getHasStagedChanges()
555  {
556  if (is_null($this->hasStagedChanges)) {
558  $data = $this->raw(self::FIELD_HAS_STAGED_CHANGES);
559  if (is_null($data)) {
560  return null;
561  }
562  $this->hasStagedChanges = (bool) $data;
563  }
564 
566  }
567 
574  public function getPublished()
575  {
576  if (is_null($this->published)) {
578  $data = $this->raw(self::FIELD_PUBLISHED);
579  if (is_null($data)) {
580  return null;
581  }
582  $this->published = (bool) $data;
583  }
584 
585  return $this->published;
586  }
587 
594  public function getMasterVariant()
595  {
596  if (is_null($this->masterVariant)) {
598  $data = $this->raw(self::FIELD_MASTER_VARIANT);
599  if (is_null($data)) {
600  return null;
601  }
602 
603  $this->masterVariant = ProductVariantModel::of($data);
604  }
605 
606  return $this->masterVariant;
607  }
608 
615  public function getVariants()
616  {
617  if (is_null($this->variants)) {
619  $data = $this->raw(self::FIELD_VARIANTS);
620  if (is_null($data)) {
621  return null;
622  }
623  $this->variants = ProductVariantCollection::fromArray($data);
624  }
625 
626  return $this->variants;
627  }
628 
635  public function getTaxCategory()
636  {
637  if (is_null($this->taxCategory)) {
639  $data = $this->raw(self::FIELD_TAX_CATEGORY);
640  if (is_null($data)) {
641  return null;
642  }
643 
644  $this->taxCategory = TaxCategoryReferenceModel::of($data);
645  }
646 
647  return $this->taxCategory;
648  }
649 
656  public function getState()
657  {
658  if (is_null($this->state)) {
660  $data = $this->raw(self::FIELD_STATE);
661  if (is_null($data)) {
662  return null;
663  }
664 
665  $this->state = StateReferenceModel::of($data);
666  }
667 
668  return $this->state;
669  }
670 
677  public function getReviewRatingStatistics()
678  {
679  if (is_null($this->reviewRatingStatistics)) {
681  $data = $this->raw(self::FIELD_REVIEW_RATING_STATISTICS);
682  if (is_null($data)) {
683  return null;
684  }
685 
686  $this->reviewRatingStatistics = ReviewRatingStatisticsModel::of($data);
687  }
688 
690  }
691 
698  public function getPriceMode()
699  {
700  if (is_null($this->priceMode)) {
702  $data = $this->raw(self::FIELD_PRICE_MODE);
703  if (is_null($data)) {
704  return null;
705  }
706  $this->priceMode = (string) $data;
707  }
708 
709  return $this->priceMode;
710  }
711 
712 
716  public function setId(?string $id): void
717  {
718  $this->id = $id;
719  }
720 
724  public function setVersion(?int $version): void
725  {
726  $this->version = $version;
727  }
728 
732  public function setCreatedAt(?DateTimeImmutable $createdAt): void
733  {
734  $this->createdAt = $createdAt;
735  }
736 
740  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
741  {
742  $this->lastModifiedAt = $lastModifiedAt;
743  }
744 
748  public function setKey(?string $key): void
749  {
750  $this->key = $key;
751  }
752 
757  {
758  $this->productType = $productType;
759  }
760 
764  public function setName(?LocalizedString $name): void
765  {
766  $this->name = $name;
767  }
768 
773  {
774  $this->description = $description;
775  }
776 
780  public function setSlug(?LocalizedString $slug): void
781  {
782  $this->slug = $slug;
783  }
784 
789  {
790  $this->categories = $categories;
791  }
792 
797  {
798  $this->categoryOrderHints = $categoryOrderHints;
799  }
800 
804  public function setMetaTitle(?LocalizedString $metaTitle): void
805  {
806  $this->metaTitle = $metaTitle;
807  }
808 
813  {
814  $this->metaDescription = $metaDescription;
815  }
816 
821  {
822  $this->metaKeywords = $metaKeywords;
823  }
824 
829  {
830  $this->searchKeywords = $searchKeywords;
831  }
832 
836  public function setHasStagedChanges(?bool $hasStagedChanges): void
837  {
838  $this->hasStagedChanges = $hasStagedChanges;
839  }
840 
844  public function setPublished(?bool $published): void
845  {
846  $this->published = $published;
847  }
848 
853  {
854  $this->masterVariant = $masterVariant;
855  }
856 
861  {
862  $this->variants = $variants;
863  }
864 
869  {
870  $this->taxCategory = $taxCategory;
871  }
872 
876  public function setState(?StateReference $state): void
877  {
878  $this->state = $state;
879  }
880 
885  {
886  $this->reviewRatingStatistics = $reviewRatingStatistics;
887  }
888 
892  public function setPriceMode(?string $priceMode): void
893  {
894  $this->priceMode = $priceMode;
895  }
896 
897 
898  #[\ReturnTypeWillChange]
899  public function jsonSerialize()
900  {
901  $data = $this->toArray();
902  if (isset($data[ProductProjection::FIELD_CREATED_AT]) && $data[ProductProjection::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
903  $data[ProductProjection::FIELD_CREATED_AT] = $data[ProductProjection::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
904  }
905 
906  if (isset($data[ProductProjection::FIELD_LAST_MODIFIED_AT]) && $data[ProductProjection::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
907  $data[ProductProjection::FIELD_LAST_MODIFIED_AT] = $data[ProductProjection::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
908  }
909  return (object) $data;
910  }
911 }
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?string $key=null, ?ProductTypeReference $productType=null, ?LocalizedString $name=null, ?LocalizedString $description=null, ?LocalizedString $slug=null, ?CategoryReferenceCollection $categories=null, ?CategoryOrderHints $categoryOrderHints=null, ?LocalizedString $metaTitle=null, ?LocalizedString $metaDescription=null, ?LocalizedString $metaKeywords=null, ?SearchKeywords $searchKeywords=null, ?bool $hasStagedChanges=null, ?bool $published=null, ?ProductVariant $masterVariant=null, ?ProductVariantCollection $variants=null, ?TaxCategoryReference $taxCategory=null, ?StateReference $state=null, ?ReviewRatingStatistics $reviewRatingStatistics=null, ?string $priceMode=null)
setCategories(?CategoryReferenceCollection $categories)
setReviewRatingStatistics(?ReviewRatingStatistics $reviewRatingStatistics)
setCategoryOrderHints(?CategoryOrderHints $categoryOrderHints)
static of($data=null)
Definition: MapperMap.php:45