commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
BusinessUnitModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
25 use DateTimeImmutable;
26 use stdClass;
27 
31 final class BusinessUnitModel extends JsonObjectModel implements BusinessUnit
32 {
33  public const DISCRIMINATOR_VALUE = '';
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 $key;
75 
80  protected $status;
81 
86  protected $stores;
87 
92  protected $storeMode;
93 
98  protected $unitType;
99 
104  protected $name;
105 
110  protected $contactEmail;
111 
116  protected $custom;
117 
122  protected $addresses;
123 
129 
135 
141 
147 
152  protected $associateMode;
153 
158  protected $associates;
159 
165 
170  protected $parentUnit;
171 
176  protected $topLevelUnit;
177 
182  protected $approvalRuleMode;
183 
188  private static $discriminatorClasses = [
189  'Company' => CompanyModel::class,
190  'Division' => DivisionModel::class,
191  ];
192 
196  public function __construct(
197  ?string $id = null,
198  ?int $version = null,
199  ?DateTimeImmutable $createdAt = null,
200  ?DateTimeImmutable $lastModifiedAt = null,
202  ?CreatedBy $createdBy = null,
203  ?string $key = null,
204  ?string $status = null,
206  ?string $storeMode = null,
207  ?string $name = null,
208  ?string $contactEmail = null,
209  ?CustomFields $custom = null,
211  ?array $shippingAddressIds = null,
212  ?string $defaultShippingAddressId = null,
213  ?array $billingAddressIds = null,
214  ?string $defaultBillingAddressId = null,
215  ?string $associateMode = null,
220  ?string $approvalRuleMode = null,
221  ?string $unitType = null
222  ) {
223  $this->id = $id;
224  $this->version = $version;
225  $this->createdAt = $createdAt;
226  $this->lastModifiedAt = $lastModifiedAt;
227  $this->lastModifiedBy = $lastModifiedBy;
228  $this->createdBy = $createdBy;
229  $this->key = $key;
230  $this->status = $status;
231  $this->stores = $stores;
232  $this->storeMode = $storeMode;
233  $this->name = $name;
234  $this->contactEmail = $contactEmail;
235  $this->custom = $custom;
236  $this->addresses = $addresses;
237  $this->shippingAddressIds = $shippingAddressIds;
238  $this->defaultShippingAddressId = $defaultShippingAddressId;
239  $this->billingAddressIds = $billingAddressIds;
240  $this->defaultBillingAddressId = $defaultBillingAddressId;
241  $this->associateMode = $associateMode;
242  $this->associates = $associates;
243  $this->inheritedAssociates = $inheritedAssociates;
244  $this->parentUnit = $parentUnit;
245  $this->topLevelUnit = $topLevelUnit;
246  $this->approvalRuleMode = $approvalRuleMode;
247  $this->unitType = $unitType;
248  }
249 
256  public function getId()
257  {
258  if (is_null($this->id)) {
260  $data = $this->raw(self::FIELD_ID);
261  if (is_null($data)) {
262  return null;
263  }
264  $this->id = (string) $data;
265  }
266 
267  return $this->id;
268  }
269 
276  public function getVersion()
277  {
278  if (is_null($this->version)) {
280  $data = $this->raw(self::FIELD_VERSION);
281  if (is_null($data)) {
282  return null;
283  }
284  $this->version = (int) $data;
285  }
286 
287  return $this->version;
288  }
289 
296  public function getCreatedAt()
297  {
298  if (is_null($this->createdAt)) {
300  $data = $this->raw(self::FIELD_CREATED_AT);
301  if (is_null($data)) {
302  return null;
303  }
304  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
305  if (false === $data) {
306  return null;
307  }
308  $this->createdAt = $data;
309  }
310 
311  return $this->createdAt;
312  }
313 
320  public function getLastModifiedAt()
321  {
322  if (is_null($this->lastModifiedAt)) {
324  $data = $this->raw(self::FIELD_LAST_MODIFIED_AT);
325  if (is_null($data)) {
326  return null;
327  }
328  $data = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, $data);
329  if (false === $data) {
330  return null;
331  }
332  $this->lastModifiedAt = $data;
333  }
334 
335  return $this->lastModifiedAt;
336  }
337 
344  public function getLastModifiedBy()
345  {
346  if (is_null($this->lastModifiedBy)) {
348  $data = $this->raw(self::FIELD_LAST_MODIFIED_BY);
349  if (is_null($data)) {
350  return null;
351  }
352 
353  $this->lastModifiedBy = LastModifiedByModel::of($data);
354  }
355 
356  return $this->lastModifiedBy;
357  }
358 
365  public function getCreatedBy()
366  {
367  if (is_null($this->createdBy)) {
369  $data = $this->raw(self::FIELD_CREATED_BY);
370  if (is_null($data)) {
371  return null;
372  }
373 
374  $this->createdBy = CreatedByModel::of($data);
375  }
376 
377  return $this->createdBy;
378  }
379 
386  public function getKey()
387  {
388  if (is_null($this->key)) {
390  $data = $this->raw(self::FIELD_KEY);
391  if (is_null($data)) {
392  return null;
393  }
394  $this->key = (string) $data;
395  }
396 
397  return $this->key;
398  }
399 
406  public function getStatus()
407  {
408  if (is_null($this->status)) {
410  $data = $this->raw(self::FIELD_STATUS);
411  if (is_null($data)) {
412  return null;
413  }
414  $this->status = (string) $data;
415  }
416 
417  return $this->status;
418  }
419 
428  public function getStores()
429  {
430  if (is_null($this->stores)) {
432  $data = $this->raw(self::FIELD_STORES);
433  if (is_null($data)) {
434  return null;
435  }
436  $this->stores = StoreKeyReferenceCollection::fromArray($data);
437  }
438 
439  return $this->stores;
440  }
441 
448  public function getStoreMode()
449  {
450  if (is_null($this->storeMode)) {
452  $data = $this->raw(self::FIELD_STORE_MODE);
453  if (is_null($data)) {
454  return null;
455  }
456  $this->storeMode = (string) $data;
457  }
458 
459  return $this->storeMode;
460  }
461 
468  public function getUnitType()
469  {
470  if (is_null($this->unitType)) {
472  $data = $this->raw(self::FIELD_UNIT_TYPE);
473  if (is_null($data)) {
474  return null;
475  }
476  $this->unitType = (string) $data;
477  }
478 
479  return $this->unitType;
480  }
481 
488  public function getName()
489  {
490  if (is_null($this->name)) {
492  $data = $this->raw(self::FIELD_NAME);
493  if (is_null($data)) {
494  return null;
495  }
496  $this->name = (string) $data;
497  }
498 
499  return $this->name;
500  }
501 
508  public function getContactEmail()
509  {
510  if (is_null($this->contactEmail)) {
512  $data = $this->raw(self::FIELD_CONTACT_EMAIL);
513  if (is_null($data)) {
514  return null;
515  }
516  $this->contactEmail = (string) $data;
517  }
518 
519  return $this->contactEmail;
520  }
521 
528  public function getCustom()
529  {
530  if (is_null($this->custom)) {
532  $data = $this->raw(self::FIELD_CUSTOM);
533  if (is_null($data)) {
534  return null;
535  }
536 
537  $this->custom = CustomFieldsModel::of($data);
538  }
539 
540  return $this->custom;
541  }
542 
549  public function getAddresses()
550  {
551  if (is_null($this->addresses)) {
553  $data = $this->raw(self::FIELD_ADDRESSES);
554  if (is_null($data)) {
555  return null;
556  }
557  $this->addresses = AddressCollection::fromArray($data);
558  }
559 
560  return $this->addresses;
561  }
562 
569  public function getShippingAddressIds()
570  {
571  if (is_null($this->shippingAddressIds)) {
573  $data = $this->raw(self::FIELD_SHIPPING_ADDRESS_IDS);
574  if (is_null($data)) {
575  return null;
576  }
577  $this->shippingAddressIds = $data;
578  }
579 
581  }
582 
589  public function getDefaultShippingAddressId()
590  {
591  if (is_null($this->defaultShippingAddressId)) {
593  $data = $this->raw(self::FIELD_DEFAULT_SHIPPING_ADDRESS_ID);
594  if (is_null($data)) {
595  return null;
596  }
597  $this->defaultShippingAddressId = (string) $data;
598  }
599 
601  }
602 
609  public function getBillingAddressIds()
610  {
611  if (is_null($this->billingAddressIds)) {
613  $data = $this->raw(self::FIELD_BILLING_ADDRESS_IDS);
614  if (is_null($data)) {
615  return null;
616  }
617  $this->billingAddressIds = $data;
618  }
619 
621  }
622 
629  public function getDefaultBillingAddressId()
630  {
631  if (is_null($this->defaultBillingAddressId)) {
633  $data = $this->raw(self::FIELD_DEFAULT_BILLING_ADDRESS_ID);
634  if (is_null($data)) {
635  return null;
636  }
637  $this->defaultBillingAddressId = (string) $data;
638  }
639 
641  }
642 
649  public function getAssociateMode()
650  {
651  if (is_null($this->associateMode)) {
653  $data = $this->raw(self::FIELD_ASSOCIATE_MODE);
654  if (is_null($data)) {
655  return null;
656  }
657  $this->associateMode = (string) $data;
658  }
659 
660  return $this->associateMode;
661  }
662 
669  public function getAssociates()
670  {
671  if (is_null($this->associates)) {
673  $data = $this->raw(self::FIELD_ASSOCIATES);
674  if (is_null($data)) {
675  return null;
676  }
677  $this->associates = AssociateCollection::fromArray($data);
678  }
679 
680  return $this->associates;
681  }
682 
689  public function getInheritedAssociates()
690  {
691  if (is_null($this->inheritedAssociates)) {
693  $data = $this->raw(self::FIELD_INHERITED_ASSOCIATES);
694  if (is_null($data)) {
695  return null;
696  }
697  $this->inheritedAssociates = InheritedAssociateCollection::fromArray($data);
698  }
699 
701  }
702 
709  public function getParentUnit()
710  {
711  if (is_null($this->parentUnit)) {
713  $data = $this->raw(self::FIELD_PARENT_UNIT);
714  if (is_null($data)) {
715  return null;
716  }
717 
718  $this->parentUnit = BusinessUnitKeyReferenceModel::of($data);
719  }
720 
721  return $this->parentUnit;
722  }
723 
730  public function getTopLevelUnit()
731  {
732  if (is_null($this->topLevelUnit)) {
734  $data = $this->raw(self::FIELD_TOP_LEVEL_UNIT);
735  if (is_null($data)) {
736  return null;
737  }
738 
739  $this->topLevelUnit = BusinessUnitKeyReferenceModel::of($data);
740  }
741 
742  return $this->topLevelUnit;
743  }
744 
752  public function getApprovalRuleMode()
753  {
754  if (is_null($this->approvalRuleMode)) {
756  $data = $this->raw(self::FIELD_APPROVAL_RULE_MODE);
757  if (is_null($data)) {
758  return null;
759  }
760  $this->approvalRuleMode = (string) $data;
761  }
762 
764  }
765 
766 
770  public function setId(?string $id): void
771  {
772  $this->id = $id;
773  }
774 
778  public function setVersion(?int $version): void
779  {
780  $this->version = $version;
781  }
782 
786  public function setCreatedAt(?DateTimeImmutable $createdAt): void
787  {
788  $this->createdAt = $createdAt;
789  }
790 
794  public function setLastModifiedAt(?DateTimeImmutable $lastModifiedAt): void
795  {
796  $this->lastModifiedAt = $lastModifiedAt;
797  }
798 
803  {
804  $this->lastModifiedBy = $lastModifiedBy;
805  }
806 
810  public function setCreatedBy(?CreatedBy $createdBy): void
811  {
812  $this->createdBy = $createdBy;
813  }
814 
818  public function setKey(?string $key): void
819  {
820  $this->key = $key;
821  }
822 
826  public function setStatus(?string $status): void
827  {
828  $this->status = $status;
829  }
830 
835  {
836  $this->stores = $stores;
837  }
838 
842  public function setStoreMode(?string $storeMode): void
843  {
844  $this->storeMode = $storeMode;
845  }
846 
850  public function setName(?string $name): void
851  {
852  $this->name = $name;
853  }
854 
858  public function setContactEmail(?string $contactEmail): void
859  {
860  $this->contactEmail = $contactEmail;
861  }
862 
866  public function setCustom(?CustomFields $custom): void
867  {
868  $this->custom = $custom;
869  }
870 
874  public function setAddresses(?AddressCollection $addresses): void
875  {
876  $this->addresses = $addresses;
877  }
878 
882  public function setShippingAddressIds(?array $shippingAddressIds): void
883  {
884  $this->shippingAddressIds = $shippingAddressIds;
885  }
886 
891  {
892  $this->defaultShippingAddressId = $defaultShippingAddressId;
893  }
894 
898  public function setBillingAddressIds(?array $billingAddressIds): void
899  {
900  $this->billingAddressIds = $billingAddressIds;
901  }
902 
907  {
908  $this->defaultBillingAddressId = $defaultBillingAddressId;
909  }
910 
914  public function setAssociateMode(?string $associateMode): void
915  {
916  $this->associateMode = $associateMode;
917  }
918 
923  {
924  $this->associates = $associates;
925  }
926 
931  {
932  $this->inheritedAssociates = $inheritedAssociates;
933  }
934 
939  {
940  $this->parentUnit = $parentUnit;
941  }
942 
947  {
948  $this->topLevelUnit = $topLevelUnit;
949  }
950 
954  public function setApprovalRuleMode(?string $approvalRuleMode): void
955  {
956  $this->approvalRuleMode = $approvalRuleMode;
957  }
958 
959 
960  #[\ReturnTypeWillChange]
961  public function jsonSerialize()
962  {
963  $data = $this->toArray();
964  if (isset($data[BusinessUnit::FIELD_CREATED_AT]) && $data[BusinessUnit::FIELD_CREATED_AT] instanceof \DateTimeImmutable) {
965  $data[BusinessUnit::FIELD_CREATED_AT] = $data[BusinessUnit::FIELD_CREATED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
966  }
967 
968  if (isset($data[BusinessUnit::FIELD_LAST_MODIFIED_AT]) && $data[BusinessUnit::FIELD_LAST_MODIFIED_AT] instanceof \DateTimeImmutable) {
969  $data[BusinessUnit::FIELD_LAST_MODIFIED_AT] = $data[BusinessUnit::FIELD_LAST_MODIFIED_AT]->setTimeZone(new \DateTimeZone('UTC'))->format('c');
970  }
971  return (object) $data;
972  }
973 
978  public static function resolveDiscriminatorClass($value): string
979  {
981  if (is_object($value) && isset($value->$fieldName)) {
983  $discriminatorValue = $value->$fieldName;
984  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
985  return self::$discriminatorClasses[$discriminatorValue];
986  }
987  }
988  if (is_array($value) && isset($value[$fieldName])) {
990  $discriminatorValue = $value[$fieldName];
991  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
992  return self::$discriminatorClasses[$discriminatorValue];
993  }
994  }
995 
997  $type = BusinessUnitModel::class;
998  return $type;
999  }
1000 }
setDefaultShippingAddressId(?string $defaultShippingAddressId)
setInheritedAssociates(?InheritedAssociateCollection $inheritedAssociates)
setTopLevelUnit(?BusinessUnitKeyReference $topLevelUnit)
setDefaultBillingAddressId(?string $defaultBillingAddressId)
__construct(?string $id=null, ?int $version=null, ?DateTimeImmutable $createdAt=null, ?DateTimeImmutable $lastModifiedAt=null, ?LastModifiedBy $lastModifiedBy=null, ?CreatedBy $createdBy=null, ?string $key=null, ?string $status=null, ?StoreKeyReferenceCollection $stores=null, ?string $storeMode=null, ?string $name=null, ?string $contactEmail=null, ?CustomFields $custom=null, ?AddressCollection $addresses=null, ?array $shippingAddressIds=null, ?string $defaultShippingAddressId=null, ?array $billingAddressIds=null, ?string $defaultBillingAddressId=null, ?string $associateMode=null, ?AssociateCollection $associates=null, ?InheritedAssociateCollection $inheritedAssociates=null, ?BusinessUnitKeyReference $parentUnit=null, ?BusinessUnitKeyReference $topLevelUnit=null, ?string $approvalRuleMode=null, ?string $unitType=null)
setParentUnit(?BusinessUnitKeyReference $parentUnit)