commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
StandalonePriceModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
32 use DateTimeImmutable;
33 use stdClass;
34 
39 {
44  protected $id;
45 
50  protected $version;
51 
56  protected $createdAt;
57 
62  protected $lastModifiedAt;
63 
68  protected $lastModifiedBy;
69 
74  protected $createdBy;
75 
80  protected $key;
81 
86  protected $sku;
87 
92  protected $value;
93 
98  protected $country;
99 
104  protected $customerGroup;
105 
110  protected $channel;
111 
116  protected $validFrom;
117 
122  protected $validUntil;
123 
128  protected $tiers;
129 
134  protected $discounted;
135 
140  protected $custom;
141 
146  protected $staged;
147 
152  protected $active;
153 
154 
158  public function __construct(
159  ?string $id = null,
160  ?int $version = null,
161  ?DateTimeImmutable $createdAt = null,
162  ?DateTimeImmutable $lastModifiedAt = null,
164  ?CreatedBy $createdBy = null,
165  ?string $key = null,
166  ?string $sku = null,
167  ?TypedMoney $value = null,
168  ?string $country = null,
170  ?ChannelReference $channel = null,
171  ?DateTimeImmutable $validFrom = null,
172  ?DateTimeImmutable $validUntil = null,
173  ?PriceTierCollection $tiers = null,
175  ?CustomFields $custom = null,
177  ?bool $active = null
178  ) {
179  $this->id = $id;
180  $this->version = $version;
181  $this->createdAt = $createdAt;
182  $this->lastModifiedAt = $lastModifiedAt;
183  $this->lastModifiedBy = $lastModifiedBy;
184  $this->createdBy = $createdBy;
185  $this->key = $key;
186  $this->sku = $sku;
187  $this->value = $value;
188  $this->country = $country;
189  $this->customerGroup = $customerGroup;
190  $this->channel = $channel;
191  $this->validFrom = $validFrom;
192  $this->validUntil = $validUntil;
193  $this->tiers = $tiers;
194  $this->discounted = $discounted;
195  $this->custom = $custom;
196  $this->staged = $staged;
197  $this->active = $active;
198  }
199 
206  public function getId()
207  {
208  if (is_null($this->id)) {
210  $data = $this->raw(self::FIELD_ID);
211  if (is_null($data)) {
212  return null;
213  }
214  $this->id = (string) $data;
215  }
216 
217  return $this->id;
218  }
219 
226  public function getVersion()
227  {
228  if (is_null($this->version)) {
230  $data = $this->raw(self::FIELD_VERSION);
231  if (is_null($data)) {
232  return null;
233  }
234  $this->version = (int) $data;
235  }
236 
237  return $this->version;
238  }
239 
246  public function getCreatedAt()
247  {
248  if (is_null($this->createdAt)) {
250  $data = $this->raw(self::FIELD_CREATED_AT);
251  if (is_null($data)) {
252  return null;
253  }
254  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
255  if (false === $data) {
256  return null;
257  }
258  $this->createdAt = $data;
259  }
260 
261  return $this->createdAt;
262  }
263 
270  public function getLastModifiedAt()
271  {
272  if (is_null($this->lastModifiedAt)) {
274  $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
275  if (is_null($data)) {
276  return null;
277  }
278  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
279  if (false === $data) {
280  return null;
281  }
282  $this->lastModifiedAt = $data;
283  }
284 
285  return $this->lastModifiedAt;
286  }
287 
294  public function getLastModifiedBy()
295  {
296  if (is_null($this->lastModifiedBy)) {
298  $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
299  if (is_null($data)) {
300  return null;
301  }
302 
303  $this->lastModifiedBy = LastModifiedByModel::of($data);
304  }
305 
306  return $this->lastModifiedBy;
307  }
308 
315  public function getCreatedBy()
316  {
317  if (is_null($this->createdBy)) {
319  $data = $this->raw(self::FIELD_CREATED_BY);
320  if (is_null($data)) {
321  return null;
322  }
323 
324  $this->createdBy = CreatedByModel::of($data);
325  }
326 
327  return $this->createdBy;
328  }
329 
336  public function getKey()
337  {
338  if (is_null($this->key)) {
340  $data = $this->raw(self::FIELD_KEY);
341  if (is_null($data)) {
342  return null;
343  }
344  $this->key = (string) $data;
345  }
346 
347  return $this->key;
348  }
349 
356  public function getSku()
357  {
358  if (is_null($this->sku)) {
360  $data = $this->raw(self::FIELD_SKU);
361  if (is_null($data)) {
362  return null;
363  }
364  $this->sku = (string) $data;
365  }
366 
367  return $this->sku;
368  }
369 
376  public function getValue()
377  {
378  if (is_null($this->value)) {
380  $data = $this->raw(self::FIELD_VALUE);
381  if (is_null($data)) {
382  return null;
383  }
384  $className = TypedMoneyModel::resolveDiscriminatorClass($data);
385  $this->value = $className::of($data);
386  }
387 
388  return $this->value;
389  }
390 
397  public function getCountry()
398  {
399  if (is_null($this->country)) {
401  $data = $this->raw(self::FIELD_COUNTRY);
402  if (is_null($data)) {
403  return null;
404  }
405  $this->country = (string) $data;
406  }
407 
408  return $this->country;
409  }
410 
417  public function getCustomerGroup()
418  {
419  if (is_null($this->customerGroup)) {
421  $data = $this->raw(self::FIELD_CUSTOMER_GROUP);
422  if (is_null($data)) {
423  return null;
424  }
425 
426  $this->customerGroup = CustomerGroupReferenceModel::of($data);
427  }
428 
429  return $this->customerGroup;
430  }
431 
438  public function getChannel()
439  {
440  if (is_null($this->channel)) {
442  $data = $this->raw(self::FIELD_CHANNEL);
443  if (is_null($data)) {
444  return null;
445  }
446 
447  $this->channel = ChannelReferenceModel::of($data);
448  }
449 
450  return $this->channel;
451  }
452 
459  public function getValidFrom()
460  {
461  if (is_null($this->validFrom)) {
463  $data = $this->raw(self::FIELD_VALID_FROM);
464  if (is_null($data)) {
465  return null;
466  }
467  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
468  if (false === $data) {
469  return null;
470  }
471  $this->validFrom = $data;
472  }
473 
474  return $this->validFrom;
475  }
476 
483  public function getValidUntil()
484  {
485  if (is_null($this->validUntil)) {
487  $data = $this->raw(self::FIELD_VALID_UNTIL);
488  if (is_null($data)) {
489  return null;
490  }
491  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
492  if (false === $data) {
493  return null;
494  }
495  $this->validUntil = $data;
496  }
497 
498  return $this->validUntil;
499  }
500 
508  public function getTiers()
509  {
510  if (is_null($this->tiers)) {
512  $data = $this->raw(self::FIELD_TIERS);
513  if (is_null($data)) {
514  return null;
515  }
516  $this->tiers = PriceTierCollection::fromArray($data);
517  }
518 
519  return $this->tiers;
520  }
521 
529  public function getDiscounted()
530  {
531  if (is_null($this->discounted)) {
533  $data = $this->raw(self::FIELD_DISCOUNTED);
534  if (is_null($data)) {
535  return null;
536  }
537 
538  $this->discounted = DiscountedPriceModel::of($data);
539  }
540 
541  return $this->discounted;
542  }
543 
550  public function getCustom()
551  {
552  if (is_null($this->custom)) {
554  $data = $this->raw(self::FIELD_CUSTOM);
555  if (is_null($data)) {
556  return null;
557  }
558 
559  $this->custom = CustomFieldsModel::of($data);
560  }
561 
562  return $this->custom;
563  }
564 
571  public function getStaged()
572  {
573  if (is_null($this->staged)) {
575  $data = $this->raw(self::FIELD_STAGED);
576  if (is_null($data)) {
577  return null;
578  }
579 
580  $this->staged = StagedStandalonePriceModel::of($data);
581  }
582 
583  return $this->staged;
584  }
585 
593  public function getActive()
594  {
595  if (is_null($this->active)) {
597  $data = $this->raw(self::FIELD_ACTIVE);
598  if (is_null($data)) {
599  return null;
600  }
601  $this->active = (bool) $data;
602  }
603 
604  return $this->active;
605  }
606 
607 
611  public function setId(?string $id): void
612  {
613  $this->id = $id;
614  }
615 
619  public function setVersion(?int $version): void
620  {
621  $this->version = $version;
622  }
623 
627  public function setCreatedAt(?DateTimeImmutable $createdAt): void
628  {
629  $this->createdAt = $createdAt;
630  }
631 
635  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
636  {
637  $this->lastModifiedAt = $lastModifiedAt;
638  }
639 
644  {
645  $this->lastModifiedBy = $lastModifiedBy;
646  }
647 
651  public function setCreatedBy(?CreatedBy $createdBy): void
652  {
653  $this->createdBy = $createdBy;
654  }
655 
659  public function setKey(?string $key): void
660  {
661  $this->key = $key;
662  }
663 
667  public function setSku(?string $sku): void
668  {
669  $this->sku = $sku;
670  }
671 
675  public function setValue(?TypedMoney $value): void
676  {
677  $this->value = $value;
678  }
679 
683  public function setCountry(?string $country): void
684  {
685  $this->country = $country;
686  }
687 
692  {
693  $this->customerGroup = $customerGroup;
694  }
695 
699  public function setChannel(?ChannelReference $channel): void
700  {
701  $this->channel = $channel;
702  }
703 
707  public function setValidFrom(?DateTimeImmutable $validFrom): void
708  {
709  $this->validFrom = $validFrom;
710  }
711 
715  public function setValidUntil(?DateTimeImmutable $validUntil): void
716  {
717  $this->validUntil = $validUntil;
718  }
719 
723  public function setTiers(?PriceTierCollection $tiers): void
724  {
725  $this->tiers = $tiers;
726  }
727 
731  public function setDiscounted(?DiscountedPrice $discounted): void
732  {
733  $this->discounted = $discounted;
734  }
735 
739  public function setCustom(?CustomFields $custom): void
740  {
741  $this->custom = $custom;
742  }
743 
747  public function setStaged(?StagedStandalonePrice $staged): void
748  {
749  $this->staged = $staged;
750  }
751 
755  public function setActive(?bool $active): void
756  {
757  $this->active = $active;
758  }
759 
760 
761  #[\ReturnTypeWillChange]
762  public function jsonSerialize()
763  {
764  $data = $this->toArray();
765  if (isset($data[StandalonePrice::FIELD_CREATED_AT]) && $data[StandalonePrice::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
766  $data[StandalonePrice::FIELD_CREATED_AT] = $data[StandalonePrice::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
767  }
768 
769  if (isset($data[StandalonePrice::FIELD_LAST_MODIFIED_AT]) && $data[StandalonePrice::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
770  $data[StandalonePrice::FIELD_LAST_MODIFIED_AT] = $data[StandalonePrice::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
771  }
772 
773  if (isset($data[StandalonePrice::FIELD_VALID_FROM]) && $data[StandalonePrice::FIELD_VALID_FROM] instanceof \DateTimeImmutable) {
774  $data[StandalonePrice::FIELD_VALID_FROM] = $data[StandalonePrice::FIELD_VALID_FROM]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
775  }
776 
777  if (isset($data[StandalonePrice::FIELD_VALID_UNTIL]) && $data[StandalonePrice::FIELD_VALID_UNTIL] instanceof \DateTimeImmutable) {
778  $data[StandalonePrice::FIELD_VALID_UNTIL] = $data[StandalonePrice::FIELD_VALID_UNTIL]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
779  }
780  return (object) $data;
781  }
782 }
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?string $key=null, ?string $sku=null, ?TypedMoney $value=null, ?string $country=null, ?CustomerGroupReference $customerGroup=null, ?ChannelReference $channel=null, ?DateTimeImmutable $validFrom=null, ?DateTimeImmutable $validUntil=null, ?PriceTierCollection $tiers=null, ?DiscountedPrice $discounted=null, ?CustomFields $custom=null, ?StagedStandalonePrice $staged=null, ?bool $active=null)