commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
VariantProjectionModel.php
1<?php
2
3declare(strict_types=1);
10
27use DateTimeImmutable;
28use stdClass;
29
34{
39 protected $id;
40
45 protected $version;
46
51 protected $createdAt;
52
57 protected $staged;
58
63 protected $variantId;
64
69 protected $product;
70
75 protected $name;
76
81 protected $slug;
82
87 protected $description;
88
93 protected $categories;
94
100
105 protected $key;
106
111 protected $sku;
112
117 protected $images;
118
123 protected $assets;
124
129 protected $attributes;
130
135 protected $price;
136
141 protected $default;
142
143
147 public function __construct(
148 ?string $id = null,
149 ?int $version = null,
150 ?DateTimeImmutable $createdAt = null,
151 ?bool $staged = null,
152 ?int $variantId = null,
154 ?LocalizedString $name = null,
155 ?LocalizedString $slug = null,
159 ?string $key = null,
160 ?string $sku = null,
161 ?ImageCollection $images = null,
162 ?AssetCollection $assets = null,
164 ?Price $price = null,
165 ?bool $default = null
166 ) {
167 $this->id = $id;
168 $this->version = $version;
169 $this->createdAt = $createdAt;
170 $this->staged = $staged;
171 $this->variantId = $variantId;
172 $this->product = $product;
173 $this->name = $name;
174 $this->slug = $slug;
175 $this->description = $description;
176 $this->categories = $categories;
177 $this->categoryOrderHints = $categoryOrderHints;
178 $this->key = $key;
179 $this->sku = $sku;
180 $this->images = $images;
181 $this->assets = $assets;
182 $this->attributes = $attributes;
183 $this->price = $price;
184 $this->default = $default;
185 }
186
193 public function getId()
194 {
195 if (is_null($this->id)) {
197 $data = $this->raw(self::FIELD_ID);
198 if (is_null($data)) {
199 return null;
200 }
201 $this->id = (string) $data;
202 }
203
204 return $this->id;
205 }
206
213 public function getVersion()
214 {
215 if (is_null($this->version)) {
217 $data = $this->raw(self::FIELD_VERSION);
218 if (is_null($data)) {
219 return null;
220 }
221 $this->version = (int) $data;
222 }
223
224 return $this->version;
225 }
226
233 public function getCreatedAt()
234 {
235 if (is_null($this->createdAt)) {
237 $data = $this->raw(self::FIELD_CREATED_AT);
238 if (is_null($data)) {
239 return null;
240 }
241 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
242 if (false === $data) {
243 return null;
244 }
245 $this->createdAt = $data;
246 }
247
248 return $this->createdAt;
249 }
250
257 public function getStaged()
258 {
259 if (is_null($this->staged)) {
261 $data = $this->raw(self::FIELD_STAGED);
262 if (is_null($data)) {
263 return null;
264 }
265 $this->staged = (bool) $data;
266 }
267
268 return $this->staged;
269 }
270
277 public function getVariantId()
278 {
279 if (is_null($this->variantId)) {
281 $data = $this->raw(self::FIELD_VARIANT_ID);
282 if (is_null($data)) {
283 return null;
284 }
285 $this->variantId = (int) $data;
286 }
287
288 return $this->variantId;
289 }
290
297 public function getProduct()
298 {
299 if (is_null($this->product)) {
301 $data = $this->raw(self::FIELD_PRODUCT);
302 if (is_null($data)) {
303 return null;
304 }
305
306 $this->product = ProductReferenceModel::of($data);
307 }
308
309 return $this->product;
310 }
311
318 public function getName()
319 {
320 if (is_null($this->name)) {
322 $data = $this->raw(self::FIELD_NAME);
323 if (is_null($data)) {
324 return null;
325 }
326
327 $this->name = LocalizedStringModel::of($data);
328 }
329
330 return $this->name;
331 }
332
339 public function getSlug()
340 {
341 if (is_null($this->slug)) {
343 $data = $this->raw(self::FIELD_SLUG);
344 if (is_null($data)) {
345 return null;
346 }
347
348 $this->slug = LocalizedStringModel::of($data);
349 }
350
351 return $this->slug;
352 }
353
360 public function getDescription()
361 {
362 if (is_null($this->description)) {
364 $data = $this->raw(self::FIELD_DESCRIPTION);
365 if (is_null($data)) {
366 return null;
367 }
368
369 $this->description = LocalizedStringModel::of($data);
370 }
371
372 return $this->description;
373 }
374
381 public function getCategories()
382 {
383 if (is_null($this->categories)) {
385 $data = $this->raw(self::FIELD_CATEGORIES);
386 if (is_null($data)) {
387 return null;
388 }
389 $this->categories = CategoryReferenceCollection::fromArray($data);
390 }
391
392 return $this->categories;
393 }
394
401 public function getCategoryOrderHints()
402 {
403 if (is_null($this->categoryOrderHints)) {
405 $data = $this->raw(self::FIELD_CATEGORY_ORDER_HINTS);
406 if (is_null($data)) {
407 return null;
408 }
409
410 $this->categoryOrderHints = CategoryOrderHintsModel::of($data);
411 }
412
414 }
415
422 public function getKey()
423 {
424 if (is_null($this->key)) {
426 $data = $this->raw(self::FIELD_KEY);
427 if (is_null($data)) {
428 return null;
429 }
430 $this->key = (string) $data;
431 }
432
433 return $this->key;
434 }
435
442 public function getSku()
443 {
444 if (is_null($this->sku)) {
446 $data = $this->raw(self::FIELD_SKU);
447 if (is_null($data)) {
448 return null;
449 }
450 $this->sku = (string) $data;
451 }
452
453 return $this->sku;
454 }
455
462 public function getImages()
463 {
464 if (is_null($this->images)) {
466 $data = $this->raw(self::FIELD_IMAGES);
467 if (is_null($data)) {
468 return null;
469 }
470 $this->images = ImageCollection::fromArray($data);
471 }
472
473 return $this->images;
474 }
475
482 public function getAssets()
483 {
484 if (is_null($this->assets)) {
486 $data = $this->raw(self::FIELD_ASSETS);
487 if (is_null($data)) {
488 return null;
489 }
490 $this->assets = AssetCollection::fromArray($data);
491 }
492
493 return $this->assets;
494 }
495
502 public function getAttributes()
503 {
504 if (is_null($this->attributes)) {
506 $data = $this->raw(self::FIELD_ATTRIBUTES);
507 if (is_null($data)) {
508 return null;
509 }
510 $this->attributes = AttributeCollection::fromArray($data);
511 }
512
513 return $this->attributes;
514 }
515
523 public function getPrice()
524 {
525 if (is_null($this->price)) {
527 $data = $this->raw(self::FIELD_PRICE);
528 if (is_null($data)) {
529 return null;
530 }
531
532 $this->price = PriceModel::of($data);
533 }
534
535 return $this->price;
536 }
537
544 public function getDefault()
545 {
546 if (is_null($this->default)) {
548 $data = $this->raw(self::FIELD_DEFAULT);
549 if (is_null($data)) {
550 return null;
551 }
552 $this->default = (bool) $data;
553 }
554
555 return $this->default;
556 }
557
558
562 public function setId(?string $id): void
563 {
564 $this->id = $id;
565 }
566
570 public function setVersion(?int $version): void
571 {
572 $this->version = $version;
573 }
574
578 public function setCreatedAt(?DateTimeImmutable $createdAt): void
579 {
580 $this->createdAt = $createdAt;
581 }
582
586 public function setStaged(?bool $staged): void
587 {
588 $this->staged = $staged;
589 }
590
594 public function setVariantId(?int $variantId): void
595 {
596 $this->variantId = $variantId;
597 }
598
602 public function setProduct(?ProductReference $product): void
603 {
604 $this->product = $product;
605 }
606
610 public function setName(?LocalizedString $name): void
611 {
612 $this->name = $name;
613 }
614
618 public function setSlug(?LocalizedString $slug): void
619 {
620 $this->slug = $slug;
621 }
622
627 {
628 $this->description = $description;
629 }
630
635 {
636 $this->categories = $categories;
637 }
638
643 {
644 $this->categoryOrderHints = $categoryOrderHints;
645 }
646
650 public function setKey(?string $key): void
651 {
652 $this->key = $key;
653 }
654
658 public function setSku(?string $sku): void
659 {
660 $this->sku = $sku;
661 }
662
666 public function setImages(?ImageCollection $images): void
667 {
668 $this->images = $images;
669 }
670
674 public function setAssets(?AssetCollection $assets): void
675 {
676 $this->assets = $assets;
677 }
678
683 {
684 $this->attributes = $attributes;
685 }
686
690 public function setPrice(?Price $price): void
691 {
692 $this->price = $price;
693 }
694
698 public function setDefault(?bool $default): void
699 {
700 $this->default = $default;
701 }
702
703
704 #[\ReturnTypeWillChange]
705 public function jsonSerialize()
706 {
707 $data = $this->toArray();
708 if (isset($data[VariantProjection::FIELD_CREATED_AT]) && $data[VariantProjection::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
709 $data[VariantProjection::FIELD_CREATED_AT] = $data[VariantProjection::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
710 }
711 return (object) $data;
712 }
713}
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?bool $staged=null, ?int $variantId=null, ?ProductReference $product=null, ?LocalizedString $name=null, ?LocalizedString $slug=null, ?LocalizedString $description=null, ?CategoryReferenceCollection $categories=null, ?CategoryOrderHints $categoryOrderHints=null, ?string $key=null, ?string $sku=null, ?ImageCollection $images=null, ?AssetCollection $assets=null, ?AttributeCollection $attributes=null, ?Price $price=null, ?bool $default=null)
setCategories(?CategoryReferenceCollection $categories)
setCategoryOrderHints(?CategoryOrderHints $categoryOrderHints)
static of($data=null)