commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ProductModel.php
1<?php
2
3declare(strict_types=1);
10
30use DateTimeImmutable;
31use stdClass;
32
36final class ProductModel extends JsonObjectModel implements Product
37{
42 protected $id;
43
48 protected $version;
49
54 protected $createdAt;
55
60 protected $lastModifiedAt;
61
66 protected $lastModifiedBy;
67
72 protected $createdBy;
73
78 protected $key;
79
84 protected $productType;
85
90 protected $masterData;
91
96 protected $taxCategory;
97
102 protected $state;
103
109
114 protected $priceMode;
115
120 protected $warnings;
121
122
126 public function __construct(
127 ?string $id = null,
128 ?int $version = null,
129 ?DateTimeImmutable $createdAt = null,
130 ?DateTimeImmutable $lastModifiedAt = null,
132 ?CreatedBy $createdBy = null,
133 ?string $key = null,
137 ?StateReference $state = null,
139 ?string $priceMode = null,
141 ) {
142 $this->id = $id;
143 $this->version = $version;
144 $this->createdAt = $createdAt;
145 $this->lastModifiedAt = $lastModifiedAt;
146 $this->lastModifiedBy = $lastModifiedBy;
147 $this->createdBy = $createdBy;
148 $this->key = $key;
149 $this->productType = $productType;
150 $this->masterData = $masterData;
151 $this->taxCategory = $taxCategory;
152 $this->state = $state;
153 $this->reviewRatingStatistics = $reviewRatingStatistics;
154 $this->priceMode = $priceMode;
155 $this->warnings = $warnings;
156 }
157
164 public function getId()
165 {
166 if (is_null($this->id)) {
168 $data = $this->raw(self::FIELD_ID);
169 if (is_null($data)) {
170 return null;
171 }
172 $this->id = (string) $data;
173 }
174
175 return $this->id;
176 }
177
184 public function getVersion()
185 {
186 if (is_null($this->version)) {
188 $data = $this->raw(self::FIELD_VERSION);
189 if (is_null($data)) {
190 return null;
191 }
192 $this->version = (int) $data;
193 }
194
195 return $this->version;
196 }
197
204 public function getCreatedAt()
205 {
206 if (is_null($this->createdAt)) {
208 $data = $this->raw(self::FIELD_CREATED_AT);
209 if (is_null($data)) {
210 return null;
211 }
212 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
213 if (false === $data) {
214 return null;
215 }
216 $this->createdAt = $data;
217 }
218
219 return $this->createdAt;
220 }
221
228 public function getLastModifiedAt()
229 {
230 if (is_null($this->lastModifiedAt)) {
232 $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
233 if (is_null($data)) {
234 return null;
235 }
236 $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
237 if (false === $data) {
238 return null;
239 }
240 $this->lastModifiedAt = $data;
241 }
242
244 }
245
252 public function getLastModifiedBy()
253 {
254 if (is_null($this->lastModifiedBy)) {
256 $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
257 if (is_null($data)) {
258 return null;
259 }
260
261 $this->lastModifiedBy = LastModifiedByModel::of($data);
262 }
263
265 }
266
273 public function getCreatedBy()
274 {
275 if (is_null($this->createdBy)) {
277 $data = $this->raw(self::FIELD_CREATED_BY);
278 if (is_null($data)) {
279 return null;
280 }
281
282 $this->createdBy = CreatedByModel::of($data);
283 }
284
285 return $this->createdBy;
286 }
287
295 public function getKey()
296 {
297 if (is_null($this->key)) {
299 $data = $this->raw(self::FIELD_KEY);
300 if (is_null($data)) {
301 return null;
302 }
303 $this->key = (string) $data;
304 }
305
306 return $this->key;
307 }
308
315 public function getProductType()
316 {
317 if (is_null($this->productType)) {
319 $data = $this->raw(self::FIELD_PRODUCT_TYPE);
320 if (is_null($data)) {
321 return null;
322 }
323
324 $this->productType = ProductTypeReferenceModel::of($data);
325 }
326
327 return $this->productType;
328 }
329
336 public function getMasterData()
337 {
338 if (is_null($this->masterData)) {
340 $data = $this->raw(self::FIELD_MASTER_DATA);
341 if (is_null($data)) {
342 return null;
343 }
344
345 $this->masterData = ProductCatalogDataModel::of($data);
346 }
347
348 return $this->masterData;
349 }
350
357 public function getTaxCategory()
358 {
359 if (is_null($this->taxCategory)) {
361 $data = $this->raw(self::FIELD_TAX_CATEGORY);
362 if (is_null($data)) {
363 return null;
364 }
365
366 $this->taxCategory = TaxCategoryReferenceModel::of($data);
367 }
368
369 return $this->taxCategory;
370 }
371
378 public function getState()
379 {
380 if (is_null($this->state)) {
382 $data = $this->raw(self::FIELD_STATE);
383 if (is_null($data)) {
384 return null;
385 }
386
387 $this->state = StateReferenceModel::of($data);
388 }
389
390 return $this->state;
391 }
392
400 {
401 if (is_null($this->reviewRatingStatistics)) {
403 $data = $this->raw(self::FIELD_REVIEW_RATING_STATISTICS);
404 if (is_null($data)) {
405 return null;
406 }
407
408 $this->reviewRatingStatistics = ReviewRatingStatisticsModel::of($data);
409 }
410
412 }
413
420 public function getPriceMode()
421 {
422 if (is_null($this->priceMode)) {
424 $data = $this->raw(self::FIELD_PRICE_MODE);
425 if (is_null($data)) {
426 return null;
427 }
428 $this->priceMode = (string) $data;
429 }
430
431 return $this->priceMode;
432 }
433
441 public function getWarnings()
442 {
443 if (is_null($this->warnings)) {
445 $data = $this->raw(self::FIELD_WARNINGS);
446 if (is_null($data)) {
447 return null;
448 }
449 $this->warnings = WarningObjectCollection::fromArray($data);
450 }
451
452 return $this->warnings;
453 }
454
455
459 public function setId(?string $id): void
460 {
461 $this->id = $id;
462 }
463
467 public function setVersion(?int $version): void
468 {
469 $this->version = $version;
470 }
471
475 public function setCreatedAt(?DateTimeImmutable $createdAt): void
476 {
477 $this->createdAt = $createdAt;
478 }
479
483 public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
484 {
485 $this->lastModifiedAt = $lastModifiedAt;
486 }
487
492 {
493 $this->lastModifiedBy = $lastModifiedBy;
494 }
495
499 public function setCreatedBy(?CreatedBy $createdBy): void
500 {
501 $this->createdBy = $createdBy;
502 }
503
507 public function setKey(?string $key): void
508 {
509 $this->key = $key;
510 }
511
516 {
517 $this->productType = $productType;
518 }
519
524 {
525 $this->masterData = $masterData;
526 }
527
532 {
533 $this->taxCategory = $taxCategory;
534 }
535
539 public function setState(?StateReference $state): void
540 {
541 $this->state = $state;
542 }
543
548 {
549 $this->reviewRatingStatistics = $reviewRatingStatistics;
550 }
551
555 public function setPriceMode(?string $priceMode): void
556 {
557 $this->priceMode = $priceMode;
558 }
559
564 {
565 $this->warnings = $warnings;
566 }
567
568
569 #[\ReturnTypeWillChange]
570 public function jsonSerialize()
571 {
572 $data = $this->toArray();
573 if (isset($data[Product::FIELD_CREATED_AT]) && $data[Product::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
574 $data[Product::FIELD_CREATED_AT] = $data[Product::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
575 }
576
577 if (isset($data[Product::FIELD_LAST_MODIFIED_AT]) && $data[Product::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
578 $data[Product::FIELD_LAST_MODIFIED_AT] = $data[Product::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
579 }
580 return (object) $data;
581 }
582}
setWarnings(?WarningObjectCollection $warnings)
setProductType(?ProductTypeReference $productType)
setMasterData(?ProductCatalogData $masterData)
setLastModifiedAt(?DateTimeImmutable $lastModifiedAt)
setLastModifiedBy(?LastModifiedBy $lastModifiedBy)
setCreatedAt(?DateTimeImmutable $createdAt)
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?string $key=null, ?ProductTypeReference $productType=null, ?ProductCatalogData $masterData=null, ?TaxCategoryReference $taxCategory=null, ?StateReference $state=null, ?ReviewRatingStatistics $reviewRatingStatistics=null, ?string $priceMode=null, ?WarningObjectCollection $warnings=null)
setReviewRatingStatistics(?ReviewRatingStatistics $reviewRatingStatistics)
setTaxCategory(?TaxCategoryReference $taxCategory)