diff --git a/changes.md b/changes.md index e167bf004a2..d7c8bf8d89f 100644 --- a/changes.md +++ b/changes.md @@ -567,18 +567,32 @@
Added Type(s) +- added type `AssociateRoleKeyReference` +- added type `BusinessUnitKeyReference` - added type `StrategyEnum` - added type `RetentionPolicy` - added type `TimeToLiveConfig` - added type `TimeToLiveRetentionPolicy` - added type `ProductSelectionImportRequest` -- added type `AttributeLevel` +- added type `BusinessUnitImportRequest` +- added type `AssociateRoleInheritanceMode` +- added type `BusinessUnitStatus` +- added type `BusinessUnitAssociateMode` +- added type `BusinessUnitApprovalRuleMode` +- added type `BusinessUnitStoreMode` +- added type `BusinessUnitType` +- added type `AssociateRoleAssignmentDraft` +- added type `AssociateDraft` +- added type `BusinessUnitImport` +- added type `CompanyBusinessUnitImport` +- added type `DivisionBusinessUnitImport` - added type `VariantSelectionType` - added type `VariantSelection` - added type `VariantExclusion` - added type `ProductSelectionAssignment` - added type `ProductSelectionMode` - added type `ProductSelectionImport` +- added type `AttributeLevel`
@@ -586,6 +600,7 @@ Added Method(s) - added method `$apiRoot->withProjectKeyValue()->productSelections()->importContainers()->withImportContainerKeyValue()->post()` +- added method `$apiRoot->withProjectKeyValue()->businessUnits()->importContainers()->withImportContainerKeyValue()->post()` @@ -593,30 +608,33 @@ Added Resource(s) - added resource `/{projectKey}/product-selections` +- added resource `/{projectKey}/business-units` - added resource `/{projectKey}/product-selections/import-containers` - added resource `/{projectKey}/product-selections/import-containers/{importContainerKey}` +- added resource `/{projectKey}/business-units/import-containers` +- added resource `/{projectKey}/business-units/import-containers/{importContainerKey}`
Changed Property(s) -- :warning: changed property `country` of type `ExternalTaxRateDraft` from type `string` to `CountryCode` - :warning: changed property `value` of type `MoneySetField` from type `Money[]` to `TypedMoney[]` +- :warning: changed property `country` of type `ExternalTaxRateDraft` from type `string` to `CountryCode`
Added Property(s) +- added property `/^[a-zA-Z]{2,3}(?:-[a-zA-Z]{4})?(?:-(?:[a-zA-Z]{2}|\d{3}))?$/` to type `LocalizedString` - added property `retentionPolicy` to type `ImportContainer` - added property `expiresAt` to type `ImportContainer` - added property `retentionPolicy` to type `ImportContainerDraft` +- added property `attributes` to type `ProductDraftImport` - added property `/^[a-zA-Z]{2,3}(?:-[a-zA-Z]{4})?(?:-(?:[a-zA-Z]{2}|\d{3}))?$/` to type `SearchKeywords` - added property `attributes` to type `ProductImport` -- added property `attributes` to type `ProductDraftImport` - added property `level` to type `AttributeDefinition` -- added property `/^[a-zA-Z]{2,3}(?:-[a-zA-Z]{4})?(?:-(?:[a-zA-Z]{2}|\d{3}))?$/` to type `LocalizedString`
@@ -631,7 +649,10 @@
Added Enum(s) +- added enum `business-unit` to type `ImportResourceType` - added enum `product-selection` to type `ImportResourceType` +- added enum `associate-role` to type `ReferenceType` +- added enum `business-unit` to type `ReferenceType`
**History changes** diff --git a/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKeyTest.php b/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKeyTest.php new file mode 100644 index 00000000000..20a1fc6dd72 --- /dev/null +++ b/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKeyTest.php @@ -0,0 +1,168 @@ +assertSame(strtolower($method), strtolower($request->getMethod())); + $this->assertSame($relativeUri, (string) $request->getUri()); + if (!is_null($body)) { + $this->assertJsonStringEqualsJsonString($body, (string) $request->getBody()); + } else { + $this->assertSame("", (string) $request->getBody()); + } + } + + + + /** + * @dataProvider getRequestBuilderResponses() + */ + public function testMapFromResponse(callable $builderFunction, $statusCode) + { + $builder = new ImportRequestBuilder(); + $request = $builderFunction($builder); + $this->assertInstanceOf(ApiRequest::class, $request); + + $response = new Response($statusCode, [], "{}"); + $this->assertInstanceOf(JsonObject::class, $request->mapFromResponse($response)); + } + + /** + * @dataProvider getRequestBuilders() + */ + public function testExecuteClientException(callable $builderFunction) + { + $client = $this->createMock(ClientInterface::class); + + $builder = new ImportRequestBuilder($client); + $request = $builderFunction($builder); + $client->method("send")->willThrowException(new ClientException("Oops!", $request, new Response(400))); + + $this->expectException(ApiClientException::class); + $request->execute(); + } + + /** + * @dataProvider getRequestBuilders() + */ + public function testExecuteServerException(callable $builderFunction) + { + $client = $this->createMock(ClientInterface::class); + + $builder = new ImportRequestBuilder($client); + $request = $builderFunction($builder); + $client->method("send")->willThrowException(new ServerException("Oops!", $request, new Response(500))); + + $this->expectException(ApiServerException::class); + $request->execute(); + } + + public function getRequests() + { + return [ + 'ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost' => [ + function (ImportRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKeyValue("test_projectKey") + ->businessUnits() + ->importContainers() + ->withImportContainerKeyValue("test_importContainerKey") + ->post(null); + }, + 'post', + 'test_projectKey/business-units/import-containers/test_importContainerKey', + ] + ]; + } + + public function getResources() + { + return [ + ]; + } + + public function getRequestBuilders() + { + return [ + 'ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost' => [ + function (ImportRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKeyValue("projectKey") + ->businessUnits() + ->importContainers() + ->withImportContainerKeyValue("importContainerKey") + ->post(null); + } + ] + ]; + } + + public function getRequestBuilderResponses() + { + return [ + 'ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost_201' => [ + function (ImportRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKeyValue("projectKey") + ->businessUnits() + ->importContainers() + ->withImportContainerKeyValue("importContainerKey") + ->post(null); + }, + 201 + ], + 'ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost_400' => [ + function (ImportRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKeyValue("projectKey") + ->businessUnits() + ->importContainers() + ->withImportContainerKeyValue("importContainerKey") + ->post(null); + }, + 400 + ], + 'ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost_599' => [ + function (ImportRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKeyValue("projectKey") + ->businessUnits() + ->importContainers() + ->withImportContainerKeyValue("importContainerKey") + ->post(null); + }, + 599 + ] + ]; + } +} diff --git a/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainersTest.php b/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainersTest.php new file mode 100644 index 00000000000..e60f1d7f1f7 --- /dev/null +++ b/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainersTest.php @@ -0,0 +1,81 @@ +assertInstanceOf($class, $resource); + $this->assertEquals($expectedArgs, $resource->getArgs()); + } + + + + + + + + public function getRequests() + { + return [ + ]; + } + + public function getResources() + { + return [ + 'ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKey' => [ + function (ImportRequestBuilder $builder): ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKey { + return $builder + ->withProjectKeyValue("test_projectKey") + ->businessUnits() + ->importContainers() + ->withImportContainerKeyValue("test_importContainerKey"); + }, + ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKey::class, + ['projectKey' => 'test_projectKey', 'importContainerKey' => 'test_importContainerKey'], + '/{projectKey}/business-units/import-containers/{importContainerKey}' + ] + ]; + } + + public function getRequestBuilders() + { + return [ + ]; + } + + public function getRequestBuilderResponses() + { + return [ + ]; + } +} diff --git a/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyBusinessUnitsTest.php b/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyBusinessUnitsTest.php new file mode 100644 index 00000000000..053d75ade9e --- /dev/null +++ b/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyBusinessUnitsTest.php @@ -0,0 +1,80 @@ +assertInstanceOf($class, $resource); + $this->assertEquals($expectedArgs, $resource->getArgs()); + } + + + + + + + + public function getRequests() + { + return [ + ]; + } + + public function getResources() + { + return [ + 'ResourceByProjectKeyBusinessUnitsImportContainers' => [ + function (ImportRequestBuilder $builder): ResourceByProjectKeyBusinessUnitsImportContainers { + return $builder + ->withProjectKeyValue("test_projectKey") + ->businessUnits() + ->importContainers(); + }, + ResourceByProjectKeyBusinessUnitsImportContainers::class, + ['projectKey' => 'test_projectKey'], + '/{projectKey}/business-units/import-containers' + ] + ]; + } + + public function getRequestBuilders() + { + return [ + ]; + } + + public function getRequestBuilderResponses() + { + return [ + ]; + } +} diff --git a/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyTest.php b/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyTest.php index e64974cfaf1..ee38e9ba5b6 100644 --- a/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyTest.php +++ b/lib/commercetools-import-tests/test/unit/Client/Resource/ResourceByProjectKeyTest.php @@ -13,6 +13,7 @@ use Commercetools\Exception\ApiClientException; use Commercetools\Exception\ApiServerException; use Commercetools\Import\Client\ImportRequestBuilder; +use Commercetools\Import\Client\Resource\ResourceByProjectKeyBusinessUnits; use Commercetools\Import\Client\Resource\ResourceByProjectKeyCategories; use Commercetools\Import\Client\Resource\ResourceByProjectKeyCustomers; use Commercetools\Import\Client\Resource\ResourceByProjectKeyDiscountCodes; @@ -237,6 +238,16 @@ function (ImportRequestBuilder $builder): ResourceByProjectKeyProductSelections ResourceByProjectKeyProductSelections::class, ['projectKey' => 'test_projectKey'], '/{projectKey}/product-selections' + ], + 'ResourceByProjectKeyBusinessUnits' => [ + function (ImportRequestBuilder $builder): ResourceByProjectKeyBusinessUnits { + return $builder + ->withProjectKeyValue("test_projectKey") + ->businessUnits(); + }, + ResourceByProjectKeyBusinessUnits::class, + ['projectKey' => 'test_projectKey'], + '/{projectKey}/business-units' ] ]; } diff --git a/lib/commercetools-import/docs/RequestBuilder.md b/lib/commercetools-import/docs/RequestBuilder.md index a1f250e6898..11b9e6443f1 100644 --- a/lib/commercetools-import/docs/RequestBuilder.md +++ b/lib/commercetools-import/docs/RequestBuilder.md @@ -8,6 +8,22 @@ use Commercetools\Import\Client\ImportRequestBuilder; $root = new ImportRequestBuilder(); ``` +## `withProjectKeyValue("projectKey")->businessUnits()->importContainers()->withImportContainerKeyValue("importContainerKey")->post(null)` + +Creates an Import Request for Business Units. + +### Example +```php +use Commercetools\Import\Client\ImportRequestBuilder; + +$builder = new ImportRequestBuilder(); +$request = $builder + ->withProjectKeyValue("projectKey") + ->businessUnits() + ->importContainers() + ->withImportContainerKeyValue("importContainerKey") + ->post(null); +``` ## `withProjectKeyValue("projectKey")->categories()->importContainers()->withImportContainerKeyValue("importContainerKey")->post(null)` Creates an Import Request for Categories. diff --git a/lib/commercetools-import/src/Client/Resource/ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost.php b/lib/commercetools-import/src/Client/Resource/ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost.php new file mode 100644 index 00000000000..783c10f7874 --- /dev/null +++ b/lib/commercetools-import/src/Client/Resource/ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost.php @@ -0,0 +1,124 @@ + + */ +class ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost extends ApiRequest implements SecuredByManageBusinessUnits +{ + /** + * @param ?object|array|string $body + * @psalm-param array $headers + */ + public function __construct(string $projectKey, string $importContainerKey, $body = null, array $headers = [], ?ClientInterface $client = null) + { + $uri = str_replace(['{projectKey}', '{importContainerKey}'], [$projectKey, $importContainerKey], '{projectKey}/business-units/import-containers/{importContainerKey}'); + parent::__construct($client, 'POST', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $resultType + * @return ErrorResponse|ImportResponse|JsonObject|T|null + */ + public function mapFromResponse(?ResponseInterface $response, ?string $resultType = null) + { + if (is_null($response)) { + return null; + } + if (is_null($resultType)) { + switch ($response->getStatusCode()) { + case '201': + $resultType = ImportResponseModel::class; + + break; + case '400': + $resultType = ErrorResponseModel::class; + + break; + default: + $resultType = JsonObjectModel::class; + + break; + } + } + + return $resultType::of($this->responseData($response)); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $resultType + * + * @return null|T|ErrorResponse|ImportResponse|JsonObject + */ + public function execute(array $options = [], ?string $resultType = null) + { + try { + $response = $this->send($options); + } catch (ServerException $e) { + $response = $e->getResponse(); + $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType)); + throw $e; + } catch (ClientException $e) { + $response = $e->getResponse(); + $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType)); + throw $e; + } + + return $this->mapFromResponse($response, $resultType); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $resultType + * + * @return PromiseInterface + */ + public function executeAsync(array $options = [], ?string $resultType = null) + { + return $this->sendAsync($options)->then( + function (ResponseInterface $response) use ($resultType) { + return $this->mapFromResponse($response, $resultType); + }, + function (RequestException $e) use ($resultType) { + $response = $e->getResponse(); + if ($e instanceof ServerException) { + $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType)); + } + if ($e instanceof ClientException) { + $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType)); + } + throw $e; + } + ); + } +} diff --git a/lib/commercetools-import/src/Client/Resource/ResourceByProjectKey.php b/lib/commercetools-import/src/Client/Resource/ResourceByProjectKey.php index c59123abbf4..281cc6efd7e 100644 --- a/lib/commercetools-import/src/Client/Resource/ResourceByProjectKey.php +++ b/lib/commercetools-import/src/Client/Resource/ResourceByProjectKey.php @@ -161,4 +161,12 @@ public function productSelections(): ResourceByProjectKeyProductSelections return new ResourceByProjectKeyProductSelections($args, $this->getClient()); } + /** + */ + public function businessUnits(): ResourceByProjectKeyBusinessUnits + { + $args = $this->getArgs(); + + return new ResourceByProjectKeyBusinessUnits($args, $this->getClient()); + } } diff --git a/lib/commercetools-import/src/Client/Resource/ResourceByProjectKeyBusinessUnits.php b/lib/commercetools-import/src/Client/Resource/ResourceByProjectKeyBusinessUnits.php new file mode 100644 index 00000000000..e13cc4e4705 --- /dev/null +++ b/lib/commercetools-import/src/Client/Resource/ResourceByProjectKeyBusinessUnits.php @@ -0,0 +1,36 @@ + $args + */ + public function __construct(array $args = [], ?ClientInterface $client = null) + { + parent::__construct('/{projectKey}/business-units', $args, $client); + } + + /** + */ + public function importContainers(): ResourceByProjectKeyBusinessUnitsImportContainers + { + $args = $this->getArgs(); + + return new ResourceByProjectKeyBusinessUnitsImportContainers($args, $this->getClient()); + } +} diff --git a/lib/commercetools-import/src/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainers.php b/lib/commercetools-import/src/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainers.php new file mode 100644 index 00000000000..65fe60a0462 --- /dev/null +++ b/lib/commercetools-import/src/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainers.php @@ -0,0 +1,39 @@ + $args + */ + public function __construct(array $args = [], ?ClientInterface $client = null) + { + parent::__construct('/{projectKey}/business-units/import-containers', $args, $client); + } + + /** + */ + public function withImportContainerKeyValue(?string $importContainerKey = null): ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKey + { + $args = $this->getArgs(); + if (!is_null($importContainerKey)) { + $args['importContainerKey'] = $importContainerKey; + } + + return new ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKey($args, $this->getClient()); + } +} diff --git a/lib/commercetools-import/src/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKey.php b/lib/commercetools-import/src/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKey.php new file mode 100644 index 00000000000..c8793de16d6 --- /dev/null +++ b/lib/commercetools-import/src/Client/Resource/ResourceByProjectKeyBusinessUnitsImportContainersByImportContainerKey.php @@ -0,0 +1,39 @@ + $args + */ + public function __construct(array $args = [], ?ClientInterface $client = null) + { + parent::__construct('/{projectKey}/business-units/import-containers/{importContainerKey}', $args, $client); + } + + /** + * @psalm-param ?BusinessUnitImportRequest $body + * @psalm-param array $headers + */ + public function post(?BusinessUnitImportRequest $body = null, array $headers = []): ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost + { + $args = $this->getArgs(); + + return new ByProjectKeyBusinessUnitsImportContainersByImportContainerKeyPost($args['projectKey'], $args['importContainerKey'], $body, $headers, $this->getClient()); + } +} diff --git a/lib/commercetools-import/src/Client/Resource/SecuredByManageBusinessUnits.php b/lib/commercetools-import/src/Client/Resource/SecuredByManageBusinessUnits.php new file mode 100644 index 00000000000..0e3a7e481a3 --- /dev/null +++ b/lib/commercetools-import/src/Client/Resource/SecuredByManageBusinessUnits.php @@ -0,0 +1,19 @@ + + */ +interface SecuredByManageBusinessUnits extends ApiRequestInterface +{ +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraft.php b/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraft.php new file mode 100644 index 00000000000..c71ed08e97e --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraft.php @@ -0,0 +1,45 @@ +The Customer to be part of the Business Unit.

+ * + + * @return null|CustomerKeyReference + */ + public function getCustomer(); + + /** + *

The roles to assign to the Associate.

+ * + + * @return null|AssociateRoleAssignmentDraftCollection + */ + public function getAssociateRoleAssignments(); + + /** + * @param ?CustomerKeyReference $customer + */ + public function setCustomer(?CustomerKeyReference $customer): void; + + /** + * @param ?AssociateRoleAssignmentDraftCollection $associateRoleAssignments + */ + public function setAssociateRoleAssignments(?AssociateRoleAssignmentDraftCollection $associateRoleAssignments): void; +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraftBuilder.php b/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraftBuilder.php new file mode 100644 index 00000000000..d1046093ec9 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraftBuilder.php @@ -0,0 +1,104 @@ + + */ +final class AssociateDraftBuilder implements Builder +{ + /** + + * @var null|CustomerKeyReference|CustomerKeyReferenceBuilder + */ + private $customer; + + /** + + * @var ?AssociateRoleAssignmentDraftCollection + */ + private $associateRoleAssignments; + + /** + *

The Customer to be part of the Business Unit.

+ * + + * @return null|CustomerKeyReference + */ + public function getCustomer() + { + return $this->customer instanceof CustomerKeyReferenceBuilder ? $this->customer->build() : $this->customer; + } + + /** + *

The roles to assign to the Associate.

+ * + + * @return null|AssociateRoleAssignmentDraftCollection + */ + public function getAssociateRoleAssignments() + { + return $this->associateRoleAssignments; + } + + /** + * @param ?CustomerKeyReference $customer + * @return $this + */ + public function withCustomer(?CustomerKeyReference $customer) + { + $this->customer = $customer; + + return $this; + } + + /** + * @param ?AssociateRoleAssignmentDraftCollection $associateRoleAssignments + * @return $this + */ + public function withAssociateRoleAssignments(?AssociateRoleAssignmentDraftCollection $associateRoleAssignments) + { + $this->associateRoleAssignments = $associateRoleAssignments; + + return $this; + } + + /** + * @deprecated use withCustomer() instead + * @return $this + */ + public function withCustomerBuilder(?CustomerKeyReferenceBuilder $customer) + { + $this->customer = $customer; + + return $this; + } + + public function build(): AssociateDraft + { + return new AssociateDraftModel( + $this->customer instanceof CustomerKeyReferenceBuilder ? $this->customer->build() : $this->customer, + $this->associateRoleAssignments + ); + } + + public static function of(): AssociateDraftBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraftCollection.php b/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraftCollection.php new file mode 100644 index 00000000000..bfe210b850f --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraftCollection.php @@ -0,0 +1,56 @@ + + * @method AssociateDraft current() + * @method AssociateDraft end() + * @method AssociateDraft at($offset) + */ +class AssociateDraftCollection extends MapperSequence +{ + /** + * @psalm-assert AssociateDraft $value + * @psalm-param AssociateDraft|stdClass $value + * @throws InvalidArgumentException + * + * @return AssociateDraftCollection + */ + public function add($value) + { + if (!$value instanceof AssociateDraft) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?AssociateDraft + */ + protected function mapper() + { + return function (?int $index): ?AssociateDraft { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var AssociateDraft $data */ + $data = AssociateDraftModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraftModel.php b/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraftModel.php new file mode 100644 index 00000000000..f540879f9b1 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/AssociateDraftModel.php @@ -0,0 +1,105 @@ +customer = $customer; + $this->associateRoleAssignments = $associateRoleAssignments; + } + + /** + *

The Customer to be part of the Business Unit.

+ * + * + * @return null|CustomerKeyReference + */ + public function getCustomer() + { + if (is_null($this->customer)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_CUSTOMER); + if (is_null($data)) { + return null; + } + + $this->customer = CustomerKeyReferenceModel::of($data); + } + + return $this->customer; + } + + /** + *

The roles to assign to the Associate.

+ * + * + * @return null|AssociateRoleAssignmentDraftCollection + */ + public function getAssociateRoleAssignments() + { + if (is_null($this->associateRoleAssignments)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_ASSOCIATE_ROLE_ASSIGNMENTS); + if (is_null($data)) { + return null; + } + $this->associateRoleAssignments = AssociateRoleAssignmentDraftCollection::fromArray($data); + } + + return $this->associateRoleAssignments; + } + + + /** + * @param ?CustomerKeyReference $customer + */ + public function setCustomer(?CustomerKeyReference $customer): void + { + $this->customer = $customer; + } + + /** + * @param ?AssociateRoleAssignmentDraftCollection $associateRoleAssignments + */ + public function setAssociateRoleAssignments(?AssociateRoleAssignmentDraftCollection $associateRoleAssignments): void + { + $this->associateRoleAssignments = $associateRoleAssignments; + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraft.php b/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraft.php new file mode 100644 index 00000000000..14e93648558 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraft.php @@ -0,0 +1,45 @@ +The role to assign to the Associate.

+ * + + * @return null|AssociateRoleKeyReference + */ + public function getAssociateRole(); + + /** + *

Determines whether the AssociateRole is inherited. If Disabled, the AssociateRole is not inherited from a parent Business Unit.

+ * + + * @return null|string + */ + public function getInheritance(); + + /** + * @param ?AssociateRoleKeyReference $associateRole + */ + public function setAssociateRole(?AssociateRoleKeyReference $associateRole): void; + + /** + * @param ?string $inheritance + */ + public function setInheritance(?string $inheritance): void; +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraftBuilder.php b/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraftBuilder.php new file mode 100644 index 00000000000..fdf63b9d006 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraftBuilder.php @@ -0,0 +1,104 @@ + + */ +final class AssociateRoleAssignmentDraftBuilder implements Builder +{ + /** + + * @var null|AssociateRoleKeyReference|AssociateRoleKeyReferenceBuilder + */ + private $associateRole; + + /** + + * @var ?string + */ + private $inheritance; + + /** + *

The role to assign to the Associate.

+ * + + * @return null|AssociateRoleKeyReference + */ + public function getAssociateRole() + { + return $this->associateRole instanceof AssociateRoleKeyReferenceBuilder ? $this->associateRole->build() : $this->associateRole; + } + + /** + *

Determines whether the AssociateRole is inherited. If Disabled, the AssociateRole is not inherited from a parent Business Unit.

+ * + + * @return null|string + */ + public function getInheritance() + { + return $this->inheritance; + } + + /** + * @param ?AssociateRoleKeyReference $associateRole + * @return $this + */ + public function withAssociateRole(?AssociateRoleKeyReference $associateRole) + { + $this->associateRole = $associateRole; + + return $this; + } + + /** + * @param ?string $inheritance + * @return $this + */ + public function withInheritance(?string $inheritance) + { + $this->inheritance = $inheritance; + + return $this; + } + + /** + * @deprecated use withAssociateRole() instead + * @return $this + */ + public function withAssociateRoleBuilder(?AssociateRoleKeyReferenceBuilder $associateRole) + { + $this->associateRole = $associateRole; + + return $this; + } + + public function build(): AssociateRoleAssignmentDraft + { + return new AssociateRoleAssignmentDraftModel( + $this->associateRole instanceof AssociateRoleKeyReferenceBuilder ? $this->associateRole->build() : $this->associateRole, + $this->inheritance + ); + } + + public static function of(): AssociateRoleAssignmentDraftBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraftCollection.php b/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraftCollection.php new file mode 100644 index 00000000000..c35688f0147 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraftCollection.php @@ -0,0 +1,56 @@ + + * @method AssociateRoleAssignmentDraft current() + * @method AssociateRoleAssignmentDraft end() + * @method AssociateRoleAssignmentDraft at($offset) + */ +class AssociateRoleAssignmentDraftCollection extends MapperSequence +{ + /** + * @psalm-assert AssociateRoleAssignmentDraft $value + * @psalm-param AssociateRoleAssignmentDraft|stdClass $value + * @throws InvalidArgumentException + * + * @return AssociateRoleAssignmentDraftCollection + */ + public function add($value) + { + if (!$value instanceof AssociateRoleAssignmentDraft) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?AssociateRoleAssignmentDraft + */ + protected function mapper() + { + return function (?int $index): ?AssociateRoleAssignmentDraft { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var AssociateRoleAssignmentDraft $data */ + $data = AssociateRoleAssignmentDraftModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraftModel.php b/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraftModel.php new file mode 100644 index 00000000000..f1324e9a7b7 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/AssociateRoleAssignmentDraftModel.php @@ -0,0 +1,105 @@ +associateRole = $associateRole; + $this->inheritance = $inheritance; + } + + /** + *

The role to assign to the Associate.

+ * + * + * @return null|AssociateRoleKeyReference + */ + public function getAssociateRole() + { + if (is_null($this->associateRole)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_ASSOCIATE_ROLE); + if (is_null($data)) { + return null; + } + + $this->associateRole = AssociateRoleKeyReferenceModel::of($data); + } + + return $this->associateRole; + } + + /** + *

Determines whether the AssociateRole is inherited. If Disabled, the AssociateRole is not inherited from a parent Business Unit.

+ * + * + * @return null|string + */ + public function getInheritance() + { + if (is_null($this->inheritance)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_INHERITANCE); + if (is_null($data)) { + return null; + } + $this->inheritance = (string) $data; + } + + return $this->inheritance; + } + + + /** + * @param ?AssociateRoleKeyReference $associateRole + */ + public function setAssociateRole(?AssociateRoleKeyReference $associateRole): void + { + $this->associateRole = $associateRole; + } + + /** + * @param ?string $inheritance + */ + public function setInheritance(?string $inheritance): void + { + $this->inheritance = $inheritance; + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImport.php b/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImport.php new file mode 100644 index 00000000000..1bfca063e53 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImport.php @@ -0,0 +1,197 @@ +The type of Business Unit.

+ * + + * @return null|string + */ + public function getUnitType(); + + /** + *

User-defined unique identifier. If a BusinessUnit with this key exists, it is updated with the imported data.

+ * + + * @return null|string + */ + public function getKey(); + + /** + *

The name of the Business Unit.

+ * + + * @return null|string + */ + public function getName(); + + /** + *

The status of the Business Unit.

+ * + + * @return null|string + */ + public function getStatus(); + + /** + *

The contact email address for the Business Unit.

+ * + + * @return null|string + */ + public function getContactEmail(); + + /** + *

List of Associates to be assigned to the Business Unit.

+ * + + * @return null|AssociateDraftCollection + */ + public function getAssociates(); + + /** + *

The addresses for the Business Unit.

+ * + + * @return null|AddressCollection + */ + public function getAddresses(); + + /** + *

The indices of the shipping addresses in the addresses array.

+ * + + * @return null|array + */ + public function getShippingAddresses(); + + /** + *

The index of the default shipping address in the addresses array.

+ * + + * @return null|int + */ + public function getDefaultShippingAddress(); + + /** + *

The indices of the billing addresses in the addresses array.

+ * + + * @return null|array + */ + public function getBillingAddresses(); + + /** + *

The index of the default billing address in the addresses array.

+ * + + * @return null|int + */ + public function getDefaultBillingAddress(); + + /** + *

The Stores of the Business Unit.

+ * + + * @return null|StoreKeyReferenceCollection + */ + public function getStores(); + + /** + *

Custom fields for the Business Unit.

+ * + + * @return null|Custom + */ + public function getCustom(); + + /** + * @param ?string $key + */ + public function setKey(?string $key): void; + + /** + * @param ?string $name + */ + public function setName(?string $name): void; + + /** + * @param ?string $status + */ + public function setStatus(?string $status): void; + + /** + * @param ?string $contactEmail + */ + public function setContactEmail(?string $contactEmail): void; + + /** + * @param ?AssociateDraftCollection $associates + */ + public function setAssociates(?AssociateDraftCollection $associates): void; + + /** + * @param ?AddressCollection $addresses + */ + public function setAddresses(?AddressCollection $addresses): void; + + /** + * @param ?array $shippingAddresses + */ + public function setShippingAddresses(?array $shippingAddresses): void; + + /** + * @param ?int $defaultShippingAddress + */ + public function setDefaultShippingAddress(?int $defaultShippingAddress): void; + + /** + * @param ?array $billingAddresses + */ + public function setBillingAddresses(?array $billingAddresses): void; + + /** + * @param ?int $defaultBillingAddress + */ + public function setDefaultBillingAddress(?int $defaultBillingAddress): void; + + /** + * @param ?StoreKeyReferenceCollection $stores + */ + public function setStores(?StoreKeyReferenceCollection $stores): void; + + /** + * @param ?Custom $custom + */ + public function setCustom(?Custom $custom): void; +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImportBuilder.php b/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImportBuilder.php new file mode 100644 index 00000000000..34277fc25cd --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImportBuilder.php @@ -0,0 +1,396 @@ + + */ +final class BusinessUnitImportBuilder implements Builder +{ + /** + + * @var ?string + */ + private $key; + + /** + + * @var ?string + */ + private $name; + + /** + + * @var ?string + */ + private $status; + + /** + + * @var ?string + */ + private $contactEmail; + + /** + + * @var ?AssociateDraftCollection + */ + private $associates; + + /** + + * @var ?AddressCollection + */ + private $addresses; + + /** + + * @var ?array + */ + private $shippingAddresses; + + /** + + * @var ?int + */ + private $defaultShippingAddress; + + /** + + * @var ?array + */ + private $billingAddresses; + + /** + + * @var ?int + */ + private $defaultBillingAddress; + + /** + + * @var ?StoreKeyReferenceCollection + */ + private $stores; + + /** + + * @var null|Custom|CustomBuilder + */ + private $custom; + + /** + *

User-defined unique identifier. If a BusinessUnit with this key exists, it is updated with the imported data.

+ * + + * @return null|string + */ + public function getKey() + { + return $this->key; + } + + /** + *

The name of the Business Unit.

+ * + + * @return null|string + */ + public function getName() + { + return $this->name; + } + + /** + *

The status of the Business Unit.

+ * + + * @return null|string + */ + public function getStatus() + { + return $this->status; + } + + /** + *

The contact email address for the Business Unit.

+ * + + * @return null|string + */ + public function getContactEmail() + { + return $this->contactEmail; + } + + /** + *

List of Associates to be assigned to the Business Unit.

+ * + + * @return null|AssociateDraftCollection + */ + public function getAssociates() + { + return $this->associates; + } + + /** + *

The addresses for the Business Unit.

+ * + + * @return null|AddressCollection + */ + public function getAddresses() + { + return $this->addresses; + } + + /** + *

The indices of the shipping addresses in the addresses array.

+ * + + * @return null|array + */ + public function getShippingAddresses() + { + return $this->shippingAddresses; + } + + /** + *

The index of the default shipping address in the addresses array.

+ * + + * @return null|int + */ + public function getDefaultShippingAddress() + { + return $this->defaultShippingAddress; + } + + /** + *

The indices of the billing addresses in the addresses array.

+ * + + * @return null|array + */ + public function getBillingAddresses() + { + return $this->billingAddresses; + } + + /** + *

The index of the default billing address in the addresses array.

+ * + + * @return null|int + */ + public function getDefaultBillingAddress() + { + return $this->defaultBillingAddress; + } + + /** + *

The Stores of the Business Unit.

+ * + + * @return null|StoreKeyReferenceCollection + */ + public function getStores() + { + return $this->stores; + } + + /** + *

Custom fields for the Business Unit.

+ * + + * @return null|Custom + */ + public function getCustom() + { + return $this->custom instanceof CustomBuilder ? $this->custom->build() : $this->custom; + } + + /** + * @param ?string $key + * @return $this + */ + public function withKey(?string $key) + { + $this->key = $key; + + return $this; + } + + /** + * @param ?string $name + * @return $this + */ + public function withName(?string $name) + { + $this->name = $name; + + return $this; + } + + /** + * @param ?string $status + * @return $this + */ + public function withStatus(?string $status) + { + $this->status = $status; + + return $this; + } + + /** + * @param ?string $contactEmail + * @return $this + */ + public function withContactEmail(?string $contactEmail) + { + $this->contactEmail = $contactEmail; + + return $this; + } + + /** + * @param ?AssociateDraftCollection $associates + * @return $this + */ + public function withAssociates(?AssociateDraftCollection $associates) + { + $this->associates = $associates; + + return $this; + } + + /** + * @param ?AddressCollection $addresses + * @return $this + */ + public function withAddresses(?AddressCollection $addresses) + { + $this->addresses = $addresses; + + return $this; + } + + /** + * @param ?array $shippingAddresses + * @return $this + */ + public function withShippingAddresses(?array $shippingAddresses) + { + $this->shippingAddresses = $shippingAddresses; + + return $this; + } + + /** + * @param ?int $defaultShippingAddress + * @return $this + */ + public function withDefaultShippingAddress(?int $defaultShippingAddress) + { + $this->defaultShippingAddress = $defaultShippingAddress; + + return $this; + } + + /** + * @param ?array $billingAddresses + * @return $this + */ + public function withBillingAddresses(?array $billingAddresses) + { + $this->billingAddresses = $billingAddresses; + + return $this; + } + + /** + * @param ?int $defaultBillingAddress + * @return $this + */ + public function withDefaultBillingAddress(?int $defaultBillingAddress) + { + $this->defaultBillingAddress = $defaultBillingAddress; + + return $this; + } + + /** + * @param ?StoreKeyReferenceCollection $stores + * @return $this + */ + public function withStores(?StoreKeyReferenceCollection $stores) + { + $this->stores = $stores; + + return $this; + } + + /** + * @param ?Custom $custom + * @return $this + */ + public function withCustom(?Custom $custom) + { + $this->custom = $custom; + + return $this; + } + + /** + * @deprecated use withCustom() instead + * @return $this + */ + public function withCustomBuilder(?CustomBuilder $custom) + { + $this->custom = $custom; + + return $this; + } + + public function build(): BusinessUnitImport + { + return new BusinessUnitImportModel( + $this->key, + $this->name, + $this->status, + $this->contactEmail, + $this->associates, + $this->addresses, + $this->shippingAddresses, + $this->defaultShippingAddress, + $this->billingAddresses, + $this->defaultBillingAddress, + $this->stores, + $this->custom instanceof CustomBuilder ? $this->custom->build() : $this->custom + ); + } + + public static function of(): BusinessUnitImportBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImportCollection.php b/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImportCollection.php new file mode 100644 index 00000000000..f8e6f9db275 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImportCollection.php @@ -0,0 +1,60 @@ + + * @psalm-method T current() + * @psalm-method T end() + * @psalm-method T at($offset) + * @method BusinessUnitImport current() + * @method BusinessUnitImport end() + * @method BusinessUnitImport at($offset) + */ +class BusinessUnitImportCollection extends MapperSequence +{ + /** + * @psalm-assert T $value + * @psalm-param T|stdClass $value + * @throws InvalidArgumentException + * + * @return BusinessUnitImportCollection + */ + public function add($value) + { + if (!$value instanceof BusinessUnitImport) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?T + */ + protected function mapper() + { + return function (?int $index): ?BusinessUnitImport { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var T $data */ + $data = BusinessUnitImportModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImportModel.php b/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImportModel.php new file mode 100644 index 00000000000..cd4a28cc90e --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/BusinessUnitImportModel.php @@ -0,0 +1,533 @@ + > + * + */ + private static $discriminatorClasses = [ + 'Company' => CompanyBusinessUnitImportModel::class, + 'Division' => DivisionBusinessUnitImportModel::class, + ]; + + /** + * @psalm-suppress MissingParamType + */ + public function __construct( + ?string $key = null, + ?string $name = null, + ?string $status = null, + ?string $contactEmail = null, + ?AssociateDraftCollection $associates = null, + ?AddressCollection $addresses = null, + ?array $shippingAddresses = null, + ?int $defaultShippingAddress = null, + ?array $billingAddresses = null, + ?int $defaultBillingAddress = null, + ?StoreKeyReferenceCollection $stores = null, + ?Custom $custom = null, + ?string $unitType = null + ) { + $this->key = $key; + $this->name = $name; + $this->status = $status; + $this->contactEmail = $contactEmail; + $this->associates = $associates; + $this->addresses = $addresses; + $this->shippingAddresses = $shippingAddresses; + $this->defaultShippingAddress = $defaultShippingAddress; + $this->billingAddresses = $billingAddresses; + $this->defaultBillingAddress = $defaultBillingAddress; + $this->stores = $stores; + $this->custom = $custom; + $this->unitType = $unitType; + } + + /** + *

The type of Business Unit.

+ * + * + * @return null|string + */ + public function getUnitType() + { + if (is_null($this->unitType)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_UNIT_TYPE); + if (is_null($data)) { + return null; + } + $this->unitType = (string) $data; + } + + return $this->unitType; + } + + /** + *

User-defined unique identifier. If a BusinessUnit with this key exists, it is updated with the imported data.

+ * + * + * @return null|string + */ + public function getKey() + { + if (is_null($this->key)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_KEY); + if (is_null($data)) { + return null; + } + $this->key = (string) $data; + } + + return $this->key; + } + + /** + *

The name of the Business Unit.

+ * + * + * @return null|string + */ + public function getName() + { + if (is_null($this->name)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_NAME); + if (is_null($data)) { + return null; + } + $this->name = (string) $data; + } + + return $this->name; + } + + /** + *

The status of the Business Unit.

+ * + * + * @return null|string + */ + public function getStatus() + { + if (is_null($this->status)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_STATUS); + if (is_null($data)) { + return null; + } + $this->status = (string) $data; + } + + return $this->status; + } + + /** + *

The contact email address for the Business Unit.

+ * + * + * @return null|string + */ + public function getContactEmail() + { + if (is_null($this->contactEmail)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_CONTACT_EMAIL); + if (is_null($data)) { + return null; + } + $this->contactEmail = (string) $data; + } + + return $this->contactEmail; + } + + /** + *

List of Associates to be assigned to the Business Unit.

+ * + * + * @return null|AssociateDraftCollection + */ + public function getAssociates() + { + if (is_null($this->associates)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_ASSOCIATES); + if (is_null($data)) { + return null; + } + $this->associates = AssociateDraftCollection::fromArray($data); + } + + return $this->associates; + } + + /** + *

The addresses for the Business Unit.

+ * + * + * @return null|AddressCollection + */ + public function getAddresses() + { + if (is_null($this->addresses)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_ADDRESSES); + if (is_null($data)) { + return null; + } + $this->addresses = AddressCollection::fromArray($data); + } + + return $this->addresses; + } + + /** + *

The indices of the shipping addresses in the addresses array.

+ * + * + * @return null|array + */ + public function getShippingAddresses() + { + if (is_null($this->shippingAddresses)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_SHIPPING_ADDRESSES); + if (is_null($data)) { + return null; + } + $this->shippingAddresses = $data; + } + + return $this->shippingAddresses; + } + + /** + *

The index of the default shipping address in the addresses array.

+ * + * + * @return null|int + */ + public function getDefaultShippingAddress() + { + if (is_null($this->defaultShippingAddress)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_DEFAULT_SHIPPING_ADDRESS); + if (is_null($data)) { + return null; + } + $this->defaultShippingAddress = (int) $data; + } + + return $this->defaultShippingAddress; + } + + /** + *

The indices of the billing addresses in the addresses array.

+ * + * + * @return null|array + */ + public function getBillingAddresses() + { + if (is_null($this->billingAddresses)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_BILLING_ADDRESSES); + if (is_null($data)) { + return null; + } + $this->billingAddresses = $data; + } + + return $this->billingAddresses; + } + + /** + *

The index of the default billing address in the addresses array.

+ * + * + * @return null|int + */ + public function getDefaultBillingAddress() + { + if (is_null($this->defaultBillingAddress)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_DEFAULT_BILLING_ADDRESS); + if (is_null($data)) { + return null; + } + $this->defaultBillingAddress = (int) $data; + } + + return $this->defaultBillingAddress; + } + + /** + *

The Stores of the Business Unit.

+ * + * + * @return null|StoreKeyReferenceCollection + */ + public function getStores() + { + if (is_null($this->stores)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_STORES); + if (is_null($data)) { + return null; + } + $this->stores = StoreKeyReferenceCollection::fromArray($data); + } + + return $this->stores; + } + + /** + *

Custom fields for the Business Unit.

+ * + * + * @return null|Custom + */ + public function getCustom() + { + if (is_null($this->custom)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_CUSTOM); + if (is_null($data)) { + return null; + } + + $this->custom = CustomModel::of($data); + } + + return $this->custom; + } + + + /** + * @param ?string $key + */ + public function setKey(?string $key): void + { + $this->key = $key; + } + + /** + * @param ?string $name + */ + public function setName(?string $name): void + { + $this->name = $name; + } + + /** + * @param ?string $status + */ + public function setStatus(?string $status): void + { + $this->status = $status; + } + + /** + * @param ?string $contactEmail + */ + public function setContactEmail(?string $contactEmail): void + { + $this->contactEmail = $contactEmail; + } + + /** + * @param ?AssociateDraftCollection $associates + */ + public function setAssociates(?AssociateDraftCollection $associates): void + { + $this->associates = $associates; + } + + /** + * @param ?AddressCollection $addresses + */ + public function setAddresses(?AddressCollection $addresses): void + { + $this->addresses = $addresses; + } + + /** + * @param ?array $shippingAddresses + */ + public function setShippingAddresses(?array $shippingAddresses): void + { + $this->shippingAddresses = $shippingAddresses; + } + + /** + * @param ?int $defaultShippingAddress + */ + public function setDefaultShippingAddress(?int $defaultShippingAddress): void + { + $this->defaultShippingAddress = $defaultShippingAddress; + } + + /** + * @param ?array $billingAddresses + */ + public function setBillingAddresses(?array $billingAddresses): void + { + $this->billingAddresses = $billingAddresses; + } + + /** + * @param ?int $defaultBillingAddress + */ + public function setDefaultBillingAddress(?int $defaultBillingAddress): void + { + $this->defaultBillingAddress = $defaultBillingAddress; + } + + /** + * @param ?StoreKeyReferenceCollection $stores + */ + public function setStores(?StoreKeyReferenceCollection $stores): void + { + $this->stores = $stores; + } + + /** + * @param ?Custom $custom + */ + public function setCustom(?Custom $custom): void + { + $this->custom = $custom; + } + + + + /** + * @psalm-param stdClass|array $value + * @psalm-return class-string + */ + public static function resolveDiscriminatorClass($value): string + { + $fieldName = BusinessUnitImport::DISCRIMINATOR_FIELD; + if (is_object($value) && isset($value->$fieldName)) { + /** @psalm-var string $discriminatorValue */ + $discriminatorValue = $value->$fieldName; + if (isset(self::$discriminatorClasses[$discriminatorValue])) { + return self::$discriminatorClasses[$discriminatorValue]; + } + } + if (is_array($value) && isset($value[$fieldName])) { + /** @psalm-var string $discriminatorValue */ + $discriminatorValue = $value[$fieldName]; + if (isset(self::$discriminatorClasses[$discriminatorValue])) { + return self::$discriminatorClasses[$discriminatorValue]; + } + } + + /** @psalm-var class-string */ + $type = BusinessUnitImportModel::class; + return $type; + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/CompanyBusinessUnitImport.php b/lib/commercetools-import/src/Models/BusinessUnits/CompanyBusinessUnitImport.php new file mode 100644 index 00000000000..b76ec7ba5c7 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/CompanyBusinessUnitImport.php @@ -0,0 +1,28 @@ + + */ +final class CompanyBusinessUnitImportBuilder implements Builder +{ + /** + + * @var ?string + */ + private $key; + + /** + + * @var ?string + */ + private $name; + + /** + + * @var ?string + */ + private $status; + + /** + + * @var ?string + */ + private $contactEmail; + + /** + + * @var ?AssociateDraftCollection + */ + private $associates; + + /** + + * @var ?AddressCollection + */ + private $addresses; + + /** + + * @var ?array + */ + private $shippingAddresses; + + /** + + * @var ?int + */ + private $defaultShippingAddress; + + /** + + * @var ?array + */ + private $billingAddresses; + + /** + + * @var ?int + */ + private $defaultBillingAddress; + + /** + + * @var ?StoreKeyReferenceCollection + */ + private $stores; + + /** + + * @var null|Custom|CustomBuilder + */ + private $custom; + + /** + + * @var ?string + */ + private $storeMode; + + /** + *

User-defined unique identifier. If a BusinessUnit with this key exists, it is updated with the imported data.

+ * + + * @return null|string + */ + public function getKey() + { + return $this->key; + } + + /** + *

The name of the Business Unit.

+ * + + * @return null|string + */ + public function getName() + { + return $this->name; + } + + /** + *

The status of the Business Unit.

+ * + + * @return null|string + */ + public function getStatus() + { + return $this->status; + } + + /** + *

The contact email address for the Business Unit.

+ * + + * @return null|string + */ + public function getContactEmail() + { + return $this->contactEmail; + } + + /** + *

List of Associates to be assigned to the Business Unit.

+ * + + * @return null|AssociateDraftCollection + */ + public function getAssociates() + { + return $this->associates; + } + + /** + *

The addresses for the Business Unit.

+ * + + * @return null|AddressCollection + */ + public function getAddresses() + { + return $this->addresses; + } + + /** + *

The indices of the shipping addresses in the addresses array.

+ * + + * @return null|array + */ + public function getShippingAddresses() + { + return $this->shippingAddresses; + } + + /** + *

The index of the default shipping address in the addresses array.

+ * + + * @return null|int + */ + public function getDefaultShippingAddress() + { + return $this->defaultShippingAddress; + } + + /** + *

The indices of the billing addresses in the addresses array.

+ * + + * @return null|array + */ + public function getBillingAddresses() + { + return $this->billingAddresses; + } + + /** + *

The index of the default billing address in the addresses array.

+ * + + * @return null|int + */ + public function getDefaultBillingAddress() + { + return $this->defaultBillingAddress; + } + + /** + *

The Stores of the Business Unit.

+ * + + * @return null|StoreKeyReferenceCollection + */ + public function getStores() + { + return $this->stores; + } + + /** + *

Custom fields for the Business Unit.

+ * + + * @return null|Custom + */ + public function getCustom() + { + return $this->custom instanceof CustomBuilder ? $this->custom->build() : $this->custom; + } + + /** + + * @return null|string + */ + public function getStoreMode() + { + return $this->storeMode; + } + + /** + * @param ?string $key + * @return $this + */ + public function withKey(?string $key) + { + $this->key = $key; + + return $this; + } + + /** + * @param ?string $name + * @return $this + */ + public function withName(?string $name) + { + $this->name = $name; + + return $this; + } + + /** + * @param ?string $status + * @return $this + */ + public function withStatus(?string $status) + { + $this->status = $status; + + return $this; + } + + /** + * @param ?string $contactEmail + * @return $this + */ + public function withContactEmail(?string $contactEmail) + { + $this->contactEmail = $contactEmail; + + return $this; + } + + /** + * @param ?AssociateDraftCollection $associates + * @return $this + */ + public function withAssociates(?AssociateDraftCollection $associates) + { + $this->associates = $associates; + + return $this; + } + + /** + * @param ?AddressCollection $addresses + * @return $this + */ + public function withAddresses(?AddressCollection $addresses) + { + $this->addresses = $addresses; + + return $this; + } + + /** + * @param ?array $shippingAddresses + * @return $this + */ + public function withShippingAddresses(?array $shippingAddresses) + { + $this->shippingAddresses = $shippingAddresses; + + return $this; + } + + /** + * @param ?int $defaultShippingAddress + * @return $this + */ + public function withDefaultShippingAddress(?int $defaultShippingAddress) + { + $this->defaultShippingAddress = $defaultShippingAddress; + + return $this; + } + + /** + * @param ?array $billingAddresses + * @return $this + */ + public function withBillingAddresses(?array $billingAddresses) + { + $this->billingAddresses = $billingAddresses; + + return $this; + } + + /** + * @param ?int $defaultBillingAddress + * @return $this + */ + public function withDefaultBillingAddress(?int $defaultBillingAddress) + { + $this->defaultBillingAddress = $defaultBillingAddress; + + return $this; + } + + /** + * @param ?StoreKeyReferenceCollection $stores + * @return $this + */ + public function withStores(?StoreKeyReferenceCollection $stores) + { + $this->stores = $stores; + + return $this; + } + + /** + * @param ?Custom $custom + * @return $this + */ + public function withCustom(?Custom $custom) + { + $this->custom = $custom; + + return $this; + } + + /** + * @param ?string $storeMode + * @return $this + */ + public function withStoreMode(?string $storeMode) + { + $this->storeMode = $storeMode; + + return $this; + } + + /** + * @deprecated use withCustom() instead + * @return $this + */ + public function withCustomBuilder(?CustomBuilder $custom) + { + $this->custom = $custom; + + return $this; + } + + public function build(): CompanyBusinessUnitImport + { + return new CompanyBusinessUnitImportModel( + $this->key, + $this->name, + $this->status, + $this->contactEmail, + $this->associates, + $this->addresses, + $this->shippingAddresses, + $this->defaultShippingAddress, + $this->billingAddresses, + $this->defaultBillingAddress, + $this->stores, + $this->custom instanceof CustomBuilder ? $this->custom->build() : $this->custom, + $this->storeMode + ); + } + + public static function of(): CompanyBusinessUnitImportBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/CompanyBusinessUnitImportCollection.php b/lib/commercetools-import/src/Models/BusinessUnits/CompanyBusinessUnitImportCollection.php new file mode 100644 index 00000000000..bb89ffc273b --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/CompanyBusinessUnitImportCollection.php @@ -0,0 +1,56 @@ + + * @method CompanyBusinessUnitImport current() + * @method CompanyBusinessUnitImport end() + * @method CompanyBusinessUnitImport at($offset) + */ +class CompanyBusinessUnitImportCollection extends BusinessUnitImportCollection +{ + /** + * @psalm-assert CompanyBusinessUnitImport $value + * @psalm-param CompanyBusinessUnitImport|stdClass $value + * @throws InvalidArgumentException + * + * @return CompanyBusinessUnitImportCollection + */ + public function add($value) + { + if (!$value instanceof CompanyBusinessUnitImport) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?CompanyBusinessUnitImport + */ + protected function mapper() + { + return function (?int $index): ?CompanyBusinessUnitImport { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var CompanyBusinessUnitImport $data */ + $data = CompanyBusinessUnitImportModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/CompanyBusinessUnitImportModel.php b/lib/commercetools-import/src/Models/BusinessUnits/CompanyBusinessUnitImportModel.php new file mode 100644 index 00000000000..2b495bfd641 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/CompanyBusinessUnitImportModel.php @@ -0,0 +1,530 @@ +key = $key; + $this->name = $name; + $this->status = $status; + $this->contactEmail = $contactEmail; + $this->associates = $associates; + $this->addresses = $addresses; + $this->shippingAddresses = $shippingAddresses; + $this->defaultShippingAddress = $defaultShippingAddress; + $this->billingAddresses = $billingAddresses; + $this->defaultBillingAddress = $defaultBillingAddress; + $this->stores = $stores; + $this->custom = $custom; + $this->storeMode = $storeMode; + $this->unitType = $unitType ?? self::DISCRIMINATOR_VALUE; + } + + /** + *

The type of Business Unit.

+ * + * + * @return null|string + */ + public function getUnitType() + { + if (is_null($this->unitType)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_UNIT_TYPE); + if (is_null($data)) { + return null; + } + $this->unitType = (string) $data; + } + + return $this->unitType; + } + + /** + *

User-defined unique identifier. If a BusinessUnit with this key exists, it is updated with the imported data.

+ * + * + * @return null|string + */ + public function getKey() + { + if (is_null($this->key)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_KEY); + if (is_null($data)) { + return null; + } + $this->key = (string) $data; + } + + return $this->key; + } + + /** + *

The name of the Business Unit.

+ * + * + * @return null|string + */ + public function getName() + { + if (is_null($this->name)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_NAME); + if (is_null($data)) { + return null; + } + $this->name = (string) $data; + } + + return $this->name; + } + + /** + *

The status of the Business Unit.

+ * + * + * @return null|string + */ + public function getStatus() + { + if (is_null($this->status)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_STATUS); + if (is_null($data)) { + return null; + } + $this->status = (string) $data; + } + + return $this->status; + } + + /** + *

The contact email address for the Business Unit.

+ * + * + * @return null|string + */ + public function getContactEmail() + { + if (is_null($this->contactEmail)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_CONTACT_EMAIL); + if (is_null($data)) { + return null; + } + $this->contactEmail = (string) $data; + } + + return $this->contactEmail; + } + + /** + *

List of Associates to be assigned to the Business Unit.

+ * + * + * @return null|AssociateDraftCollection + */ + public function getAssociates() + { + if (is_null($this->associates)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_ASSOCIATES); + if (is_null($data)) { + return null; + } + $this->associates = AssociateDraftCollection::fromArray($data); + } + + return $this->associates; + } + + /** + *

The addresses for the Business Unit.

+ * + * + * @return null|AddressCollection + */ + public function getAddresses() + { + if (is_null($this->addresses)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_ADDRESSES); + if (is_null($data)) { + return null; + } + $this->addresses = AddressCollection::fromArray($data); + } + + return $this->addresses; + } + + /** + *

The indices of the shipping addresses in the addresses array.

+ * + * + * @return null|array + */ + public function getShippingAddresses() + { + if (is_null($this->shippingAddresses)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_SHIPPING_ADDRESSES); + if (is_null($data)) { + return null; + } + $this->shippingAddresses = $data; + } + + return $this->shippingAddresses; + } + + /** + *

The index of the default shipping address in the addresses array.

+ * + * + * @return null|int + */ + public function getDefaultShippingAddress() + { + if (is_null($this->defaultShippingAddress)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_DEFAULT_SHIPPING_ADDRESS); + if (is_null($data)) { + return null; + } + $this->defaultShippingAddress = (int) $data; + } + + return $this->defaultShippingAddress; + } + + /** + *

The indices of the billing addresses in the addresses array.

+ * + * + * @return null|array + */ + public function getBillingAddresses() + { + if (is_null($this->billingAddresses)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_BILLING_ADDRESSES); + if (is_null($data)) { + return null; + } + $this->billingAddresses = $data; + } + + return $this->billingAddresses; + } + + /** + *

The index of the default billing address in the addresses array.

+ * + * + * @return null|int + */ + public function getDefaultBillingAddress() + { + if (is_null($this->defaultBillingAddress)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_DEFAULT_BILLING_ADDRESS); + if (is_null($data)) { + return null; + } + $this->defaultBillingAddress = (int) $data; + } + + return $this->defaultBillingAddress; + } + + /** + *

The Stores of the Business Unit.

+ * + * + * @return null|StoreKeyReferenceCollection + */ + public function getStores() + { + if (is_null($this->stores)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_STORES); + if (is_null($data)) { + return null; + } + $this->stores = StoreKeyReferenceCollection::fromArray($data); + } + + return $this->stores; + } + + /** + *

Custom fields for the Business Unit.

+ * + * + * @return null|Custom + */ + public function getCustom() + { + if (is_null($this->custom)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_CUSTOM); + if (is_null($data)) { + return null; + } + + $this->custom = CustomModel::of($data); + } + + return $this->custom; + } + + /** + * + * @return null|string + */ + public function getStoreMode() + { + if (is_null($this->storeMode)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_STORE_MODE); + if (is_null($data)) { + return null; + } + $this->storeMode = (string) $data; + } + + return $this->storeMode; + } + + + /** + * @param ?string $key + */ + public function setKey(?string $key): void + { + $this->key = $key; + } + + /** + * @param ?string $name + */ + public function setName(?string $name): void + { + $this->name = $name; + } + + /** + * @param ?string $status + */ + public function setStatus(?string $status): void + { + $this->status = $status; + } + + /** + * @param ?string $contactEmail + */ + public function setContactEmail(?string $contactEmail): void + { + $this->contactEmail = $contactEmail; + } + + /** + * @param ?AssociateDraftCollection $associates + */ + public function setAssociates(?AssociateDraftCollection $associates): void + { + $this->associates = $associates; + } + + /** + * @param ?AddressCollection $addresses + */ + public function setAddresses(?AddressCollection $addresses): void + { + $this->addresses = $addresses; + } + + /** + * @param ?array $shippingAddresses + */ + public function setShippingAddresses(?array $shippingAddresses): void + { + $this->shippingAddresses = $shippingAddresses; + } + + /** + * @param ?int $defaultShippingAddress + */ + public function setDefaultShippingAddress(?int $defaultShippingAddress): void + { + $this->defaultShippingAddress = $defaultShippingAddress; + } + + /** + * @param ?array $billingAddresses + */ + public function setBillingAddresses(?array $billingAddresses): void + { + $this->billingAddresses = $billingAddresses; + } + + /** + * @param ?int $defaultBillingAddress + */ + public function setDefaultBillingAddress(?int $defaultBillingAddress): void + { + $this->defaultBillingAddress = $defaultBillingAddress; + } + + /** + * @param ?StoreKeyReferenceCollection $stores + */ + public function setStores(?StoreKeyReferenceCollection $stores): void + { + $this->stores = $stores; + } + + /** + * @param ?Custom $custom + */ + public function setCustom(?Custom $custom): void + { + $this->custom = $custom; + } + + /** + * @param ?string $storeMode + */ + public function setStoreMode(?string $storeMode): void + { + $this->storeMode = $storeMode; + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImport.php b/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImport.php new file mode 100644 index 00000000000..d5d74030759 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImport.php @@ -0,0 +1,73 @@ +If Explicit, the stores field cannot be empty and the Business Unit is explicitly associated with the given Stores. If FromParent, the Business Unit inherits the Stores from its parent.

+ * + + * @return null|string + */ + public function getStoreMode(); + + /** + *

The parent Business Unit of this Division.

+ * + + * @return null|BusinessUnitKeyReference + */ + public function getParentUnit(); + + /** + *

If Explicit, Associates are not inherited from the parent. If ExplicitAndFromParent, Associates are inherited from the parent.

+ * + + * @return null|string + */ + public function getAssociateMode(); + + /** + *

If Explicit, approval rules are not inherited from the parent. If ExplicitAndFromParent, approval rules are inherited from the parent.

+ * + + * @return null|string + */ + public function getApprovalRuleMode(); + + /** + * @param ?string $storeMode + */ + public function setStoreMode(?string $storeMode): void; + + /** + * @param ?BusinessUnitKeyReference $parentUnit + */ + public function setParentUnit(?BusinessUnitKeyReference $parentUnit): void; + + /** + * @param ?string $associateMode + */ + public function setAssociateMode(?string $associateMode): void; + + /** + * @param ?string $approvalRuleMode + */ + public function setApprovalRuleMode(?string $approvalRuleMode): void; +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImportBuilder.php b/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImportBuilder.php new file mode 100644 index 00000000000..bc59ffd3008 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImportBuilder.php @@ -0,0 +1,525 @@ + + */ +final class DivisionBusinessUnitImportBuilder implements Builder +{ + /** + + * @var ?string + */ + private $key; + + /** + + * @var ?string + */ + private $name; + + /** + + * @var ?string + */ + private $status; + + /** + + * @var ?string + */ + private $contactEmail; + + /** + + * @var ?AssociateDraftCollection + */ + private $associates; + + /** + + * @var ?AddressCollection + */ + private $addresses; + + /** + + * @var ?array + */ + private $shippingAddresses; + + /** + + * @var ?int + */ + private $defaultShippingAddress; + + /** + + * @var ?array + */ + private $billingAddresses; + + /** + + * @var ?int + */ + private $defaultBillingAddress; + + /** + + * @var ?StoreKeyReferenceCollection + */ + private $stores; + + /** + + * @var null|Custom|CustomBuilder + */ + private $custom; + + /** + + * @var ?string + */ + private $storeMode; + + /** + + * @var null|BusinessUnitKeyReference|BusinessUnitKeyReferenceBuilder + */ + private $parentUnit; + + /** + + * @var ?string + */ + private $associateMode; + + /** + + * @var ?string + */ + private $approvalRuleMode; + + /** + *

User-defined unique identifier. If a BusinessUnit with this key exists, it is updated with the imported data.

+ * + + * @return null|string + */ + public function getKey() + { + return $this->key; + } + + /** + *

The name of the Business Unit.

+ * + + * @return null|string + */ + public function getName() + { + return $this->name; + } + + /** + *

The status of the Business Unit.

+ * + + * @return null|string + */ + public function getStatus() + { + return $this->status; + } + + /** + *

The contact email address for the Business Unit.

+ * + + * @return null|string + */ + public function getContactEmail() + { + return $this->contactEmail; + } + + /** + *

List of Associates to be assigned to the Business Unit.

+ * + + * @return null|AssociateDraftCollection + */ + public function getAssociates() + { + return $this->associates; + } + + /** + *

The addresses for the Business Unit.

+ * + + * @return null|AddressCollection + */ + public function getAddresses() + { + return $this->addresses; + } + + /** + *

The indices of the shipping addresses in the addresses array.

+ * + + * @return null|array + */ + public function getShippingAddresses() + { + return $this->shippingAddresses; + } + + /** + *

The index of the default shipping address in the addresses array.

+ * + + * @return null|int + */ + public function getDefaultShippingAddress() + { + return $this->defaultShippingAddress; + } + + /** + *

The indices of the billing addresses in the addresses array.

+ * + + * @return null|array + */ + public function getBillingAddresses() + { + return $this->billingAddresses; + } + + /** + *

The index of the default billing address in the addresses array.

+ * + + * @return null|int + */ + public function getDefaultBillingAddress() + { + return $this->defaultBillingAddress; + } + + /** + *

The Stores of the Business Unit.

+ * + + * @return null|StoreKeyReferenceCollection + */ + public function getStores() + { + return $this->stores; + } + + /** + *

Custom fields for the Business Unit.

+ * + + * @return null|Custom + */ + public function getCustom() + { + return $this->custom instanceof CustomBuilder ? $this->custom->build() : $this->custom; + } + + /** + *

If Explicit, the stores field cannot be empty and the Business Unit is explicitly associated with the given Stores. If FromParent, the Business Unit inherits the Stores from its parent.

+ * + + * @return null|string + */ + public function getStoreMode() + { + return $this->storeMode; + } + + /** + *

The parent Business Unit of this Division.

+ * + + * @return null|BusinessUnitKeyReference + */ + public function getParentUnit() + { + return $this->parentUnit instanceof BusinessUnitKeyReferenceBuilder ? $this->parentUnit->build() : $this->parentUnit; + } + + /** + *

If Explicit, Associates are not inherited from the parent. If ExplicitAndFromParent, Associates are inherited from the parent.

+ * + + * @return null|string + */ + public function getAssociateMode() + { + return $this->associateMode; + } + + /** + *

If Explicit, approval rules are not inherited from the parent. If ExplicitAndFromParent, approval rules are inherited from the parent.

+ * + + * @return null|string + */ + public function getApprovalRuleMode() + { + return $this->approvalRuleMode; + } + + /** + * @param ?string $key + * @return $this + */ + public function withKey(?string $key) + { + $this->key = $key; + + return $this; + } + + /** + * @param ?string $name + * @return $this + */ + public function withName(?string $name) + { + $this->name = $name; + + return $this; + } + + /** + * @param ?string $status + * @return $this + */ + public function withStatus(?string $status) + { + $this->status = $status; + + return $this; + } + + /** + * @param ?string $contactEmail + * @return $this + */ + public function withContactEmail(?string $contactEmail) + { + $this->contactEmail = $contactEmail; + + return $this; + } + + /** + * @param ?AssociateDraftCollection $associates + * @return $this + */ + public function withAssociates(?AssociateDraftCollection $associates) + { + $this->associates = $associates; + + return $this; + } + + /** + * @param ?AddressCollection $addresses + * @return $this + */ + public function withAddresses(?AddressCollection $addresses) + { + $this->addresses = $addresses; + + return $this; + } + + /** + * @param ?array $shippingAddresses + * @return $this + */ + public function withShippingAddresses(?array $shippingAddresses) + { + $this->shippingAddresses = $shippingAddresses; + + return $this; + } + + /** + * @param ?int $defaultShippingAddress + * @return $this + */ + public function withDefaultShippingAddress(?int $defaultShippingAddress) + { + $this->defaultShippingAddress = $defaultShippingAddress; + + return $this; + } + + /** + * @param ?array $billingAddresses + * @return $this + */ + public function withBillingAddresses(?array $billingAddresses) + { + $this->billingAddresses = $billingAddresses; + + return $this; + } + + /** + * @param ?int $defaultBillingAddress + * @return $this + */ + public function withDefaultBillingAddress(?int $defaultBillingAddress) + { + $this->defaultBillingAddress = $defaultBillingAddress; + + return $this; + } + + /** + * @param ?StoreKeyReferenceCollection $stores + * @return $this + */ + public function withStores(?StoreKeyReferenceCollection $stores) + { + $this->stores = $stores; + + return $this; + } + + /** + * @param ?Custom $custom + * @return $this + */ + public function withCustom(?Custom $custom) + { + $this->custom = $custom; + + return $this; + } + + /** + * @param ?string $storeMode + * @return $this + */ + public function withStoreMode(?string $storeMode) + { + $this->storeMode = $storeMode; + + return $this; + } + + /** + * @param ?BusinessUnitKeyReference $parentUnit + * @return $this + */ + public function withParentUnit(?BusinessUnitKeyReference $parentUnit) + { + $this->parentUnit = $parentUnit; + + return $this; + } + + /** + * @param ?string $associateMode + * @return $this + */ + public function withAssociateMode(?string $associateMode) + { + $this->associateMode = $associateMode; + + return $this; + } + + /** + * @param ?string $approvalRuleMode + * @return $this + */ + public function withApprovalRuleMode(?string $approvalRuleMode) + { + $this->approvalRuleMode = $approvalRuleMode; + + return $this; + } + + /** + * @deprecated use withCustom() instead + * @return $this + */ + public function withCustomBuilder(?CustomBuilder $custom) + { + $this->custom = $custom; + + return $this; + } + + /** + * @deprecated use withParentUnit() instead + * @return $this + */ + public function withParentUnitBuilder(?BusinessUnitKeyReferenceBuilder $parentUnit) + { + $this->parentUnit = $parentUnit; + + return $this; + } + + public function build(): DivisionBusinessUnitImport + { + return new DivisionBusinessUnitImportModel( + $this->key, + $this->name, + $this->status, + $this->contactEmail, + $this->associates, + $this->addresses, + $this->shippingAddresses, + $this->defaultShippingAddress, + $this->billingAddresses, + $this->defaultBillingAddress, + $this->stores, + $this->custom instanceof CustomBuilder ? $this->custom->build() : $this->custom, + $this->storeMode, + $this->parentUnit instanceof BusinessUnitKeyReferenceBuilder ? $this->parentUnit->build() : $this->parentUnit, + $this->associateMode, + $this->approvalRuleMode + ); + } + + public static function of(): DivisionBusinessUnitImportBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImportCollection.php b/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImportCollection.php new file mode 100644 index 00000000000..2f7c1668440 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImportCollection.php @@ -0,0 +1,56 @@ + + * @method DivisionBusinessUnitImport current() + * @method DivisionBusinessUnitImport end() + * @method DivisionBusinessUnitImport at($offset) + */ +class DivisionBusinessUnitImportCollection extends BusinessUnitImportCollection +{ + /** + * @psalm-assert DivisionBusinessUnitImport $value + * @psalm-param DivisionBusinessUnitImport|stdClass $value + * @throws InvalidArgumentException + * + * @return DivisionBusinessUnitImportCollection + */ + public function add($value) + { + if (!$value instanceof DivisionBusinessUnitImport) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?DivisionBusinessUnitImport + */ + protected function mapper() + { + return function (?int $index): ?DivisionBusinessUnitImport { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var DivisionBusinessUnitImport $data */ + $data = DivisionBusinessUnitImportModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImportModel.php b/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImportModel.php new file mode 100644 index 00000000000..71b72c19026 --- /dev/null +++ b/lib/commercetools-import/src/Models/BusinessUnits/DivisionBusinessUnitImportModel.php @@ -0,0 +1,643 @@ +key = $key; + $this->name = $name; + $this->status = $status; + $this->contactEmail = $contactEmail; + $this->associates = $associates; + $this->addresses = $addresses; + $this->shippingAddresses = $shippingAddresses; + $this->defaultShippingAddress = $defaultShippingAddress; + $this->billingAddresses = $billingAddresses; + $this->defaultBillingAddress = $defaultBillingAddress; + $this->stores = $stores; + $this->custom = $custom; + $this->storeMode = $storeMode; + $this->parentUnit = $parentUnit; + $this->associateMode = $associateMode; + $this->approvalRuleMode = $approvalRuleMode; + $this->unitType = $unitType ?? self::DISCRIMINATOR_VALUE; + } + + /** + *

The type of Business Unit.

+ * + * + * @return null|string + */ + public function getUnitType() + { + if (is_null($this->unitType)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_UNIT_TYPE); + if (is_null($data)) { + return null; + } + $this->unitType = (string) $data; + } + + return $this->unitType; + } + + /** + *

User-defined unique identifier. If a BusinessUnit with this key exists, it is updated with the imported data.

+ * + * + * @return null|string + */ + public function getKey() + { + if (is_null($this->key)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_KEY); + if (is_null($data)) { + return null; + } + $this->key = (string) $data; + } + + return $this->key; + } + + /** + *

The name of the Business Unit.

+ * + * + * @return null|string + */ + public function getName() + { + if (is_null($this->name)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_NAME); + if (is_null($data)) { + return null; + } + $this->name = (string) $data; + } + + return $this->name; + } + + /** + *

The status of the Business Unit.

+ * + * + * @return null|string + */ + public function getStatus() + { + if (is_null($this->status)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_STATUS); + if (is_null($data)) { + return null; + } + $this->status = (string) $data; + } + + return $this->status; + } + + /** + *

The contact email address for the Business Unit.

+ * + * + * @return null|string + */ + public function getContactEmail() + { + if (is_null($this->contactEmail)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_CONTACT_EMAIL); + if (is_null($data)) { + return null; + } + $this->contactEmail = (string) $data; + } + + return $this->contactEmail; + } + + /** + *

List of Associates to be assigned to the Business Unit.

+ * + * + * @return null|AssociateDraftCollection + */ + public function getAssociates() + { + if (is_null($this->associates)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_ASSOCIATES); + if (is_null($data)) { + return null; + } + $this->associates = AssociateDraftCollection::fromArray($data); + } + + return $this->associates; + } + + /** + *

The addresses for the Business Unit.

+ * + * + * @return null|AddressCollection + */ + public function getAddresses() + { + if (is_null($this->addresses)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_ADDRESSES); + if (is_null($data)) { + return null; + } + $this->addresses = AddressCollection::fromArray($data); + } + + return $this->addresses; + } + + /** + *

The indices of the shipping addresses in the addresses array.

+ * + * + * @return null|array + */ + public function getShippingAddresses() + { + if (is_null($this->shippingAddresses)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_SHIPPING_ADDRESSES); + if (is_null($data)) { + return null; + } + $this->shippingAddresses = $data; + } + + return $this->shippingAddresses; + } + + /** + *

The index of the default shipping address in the addresses array.

+ * + * + * @return null|int + */ + public function getDefaultShippingAddress() + { + if (is_null($this->defaultShippingAddress)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_DEFAULT_SHIPPING_ADDRESS); + if (is_null($data)) { + return null; + } + $this->defaultShippingAddress = (int) $data; + } + + return $this->defaultShippingAddress; + } + + /** + *

The indices of the billing addresses in the addresses array.

+ * + * + * @return null|array + */ + public function getBillingAddresses() + { + if (is_null($this->billingAddresses)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_BILLING_ADDRESSES); + if (is_null($data)) { + return null; + } + $this->billingAddresses = $data; + } + + return $this->billingAddresses; + } + + /** + *

The index of the default billing address in the addresses array.

+ * + * + * @return null|int + */ + public function getDefaultBillingAddress() + { + if (is_null($this->defaultBillingAddress)) { + /** @psalm-var ?int $data */ + $data = $this->raw(self::FIELD_DEFAULT_BILLING_ADDRESS); + if (is_null($data)) { + return null; + } + $this->defaultBillingAddress = (int) $data; + } + + return $this->defaultBillingAddress; + } + + /** + *

The Stores of the Business Unit.

+ * + * + * @return null|StoreKeyReferenceCollection + */ + public function getStores() + { + if (is_null($this->stores)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_STORES); + if (is_null($data)) { + return null; + } + $this->stores = StoreKeyReferenceCollection::fromArray($data); + } + + return $this->stores; + } + + /** + *

Custom fields for the Business Unit.

+ * + * + * @return null|Custom + */ + public function getCustom() + { + if (is_null($this->custom)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_CUSTOM); + if (is_null($data)) { + return null; + } + + $this->custom = CustomModel::of($data); + } + + return $this->custom; + } + + /** + *

If Explicit, the stores field cannot be empty and the Business Unit is explicitly associated with the given Stores. If FromParent, the Business Unit inherits the Stores from its parent.

+ * + * + * @return null|string + */ + public function getStoreMode() + { + if (is_null($this->storeMode)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_STORE_MODE); + if (is_null($data)) { + return null; + } + $this->storeMode = (string) $data; + } + + return $this->storeMode; + } + + /** + *

The parent Business Unit of this Division.

+ * + * + * @return null|BusinessUnitKeyReference + */ + public function getParentUnit() + { + if (is_null($this->parentUnit)) { + /** @psalm-var stdClass|array|null $data */ + $data = $this->raw(self::FIELD_PARENT_UNIT); + if (is_null($data)) { + return null; + } + + $this->parentUnit = BusinessUnitKeyReferenceModel::of($data); + } + + return $this->parentUnit; + } + + /** + *

If Explicit, Associates are not inherited from the parent. If ExplicitAndFromParent, Associates are inherited from the parent.

+ * + * + * @return null|string + */ + public function getAssociateMode() + { + if (is_null($this->associateMode)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_ASSOCIATE_MODE); + if (is_null($data)) { + return null; + } + $this->associateMode = (string) $data; + } + + return $this->associateMode; + } + + /** + *

If Explicit, approval rules are not inherited from the parent. If ExplicitAndFromParent, approval rules are inherited from the parent.

+ * + * + * @return null|string + */ + public function getApprovalRuleMode() + { + if (is_null($this->approvalRuleMode)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_APPROVAL_RULE_MODE); + if (is_null($data)) { + return null; + } + $this->approvalRuleMode = (string) $data; + } + + return $this->approvalRuleMode; + } + + + /** + * @param ?string $key + */ + public function setKey(?string $key): void + { + $this->key = $key; + } + + /** + * @param ?string $name + */ + public function setName(?string $name): void + { + $this->name = $name; + } + + /** + * @param ?string $status + */ + public function setStatus(?string $status): void + { + $this->status = $status; + } + + /** + * @param ?string $contactEmail + */ + public function setContactEmail(?string $contactEmail): void + { + $this->contactEmail = $contactEmail; + } + + /** + * @param ?AssociateDraftCollection $associates + */ + public function setAssociates(?AssociateDraftCollection $associates): void + { + $this->associates = $associates; + } + + /** + * @param ?AddressCollection $addresses + */ + public function setAddresses(?AddressCollection $addresses): void + { + $this->addresses = $addresses; + } + + /** + * @param ?array $shippingAddresses + */ + public function setShippingAddresses(?array $shippingAddresses): void + { + $this->shippingAddresses = $shippingAddresses; + } + + /** + * @param ?int $defaultShippingAddress + */ + public function setDefaultShippingAddress(?int $defaultShippingAddress): void + { + $this->defaultShippingAddress = $defaultShippingAddress; + } + + /** + * @param ?array $billingAddresses + */ + public function setBillingAddresses(?array $billingAddresses): void + { + $this->billingAddresses = $billingAddresses; + } + + /** + * @param ?int $defaultBillingAddress + */ + public function setDefaultBillingAddress(?int $defaultBillingAddress): void + { + $this->defaultBillingAddress = $defaultBillingAddress; + } + + /** + * @param ?StoreKeyReferenceCollection $stores + */ + public function setStores(?StoreKeyReferenceCollection $stores): void + { + $this->stores = $stores; + } + + /** + * @param ?Custom $custom + */ + public function setCustom(?Custom $custom): void + { + $this->custom = $custom; + } + + /** + * @param ?string $storeMode + */ + public function setStoreMode(?string $storeMode): void + { + $this->storeMode = $storeMode; + } + + /** + * @param ?BusinessUnitKeyReference $parentUnit + */ + public function setParentUnit(?BusinessUnitKeyReference $parentUnit): void + { + $this->parentUnit = $parentUnit; + } + + /** + * @param ?string $associateMode + */ + public function setAssociateMode(?string $associateMode): void + { + $this->associateMode = $associateMode; + } + + /** + * @param ?string $approvalRuleMode + */ + public function setApprovalRuleMode(?string $approvalRuleMode): void + { + $this->approvalRuleMode = $approvalRuleMode; + } +} diff --git a/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReference.php b/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReference.php new file mode 100644 index 00000000000..d7ba5acda01 --- /dev/null +++ b/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReference.php @@ -0,0 +1,28 @@ +User-defined unique identifier of the referenced Type.

+ * + + * @return null|string + */ + public function getKey(); + + /** + * @param ?string $key + */ + public function setKey(?string $key): void; +} diff --git a/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReferenceBuilder.php b/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReferenceBuilder.php new file mode 100644 index 00000000000..b6209bd97d0 --- /dev/null +++ b/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReferenceBuilder.php @@ -0,0 +1,63 @@ + + */ +final class AssociateRoleKeyReferenceBuilder implements Builder +{ + /** + + * @var ?string + */ + private $key; + + /** + *

User-defined unique identifier of the referenced Type.

+ * + + * @return null|string + */ + public function getKey() + { + return $this->key; + } + + /** + * @param ?string $key + * @return $this + */ + public function withKey(?string $key) + { + $this->key = $key; + + return $this; + } + + + public function build(): AssociateRoleKeyReference + { + return new AssociateRoleKeyReferenceModel( + $this->key + ); + } + + public static function of(): AssociateRoleKeyReferenceBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReferenceCollection.php b/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReferenceCollection.php new file mode 100644 index 00000000000..920c4afd852 --- /dev/null +++ b/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReferenceCollection.php @@ -0,0 +1,56 @@ + + * @method AssociateRoleKeyReference current() + * @method AssociateRoleKeyReference end() + * @method AssociateRoleKeyReference at($offset) + */ +class AssociateRoleKeyReferenceCollection extends KeyReferenceCollection +{ + /** + * @psalm-assert AssociateRoleKeyReference $value + * @psalm-param AssociateRoleKeyReference|stdClass $value + * @throws InvalidArgumentException + * + * @return AssociateRoleKeyReferenceCollection + */ + public function add($value) + { + if (!$value instanceof AssociateRoleKeyReference) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?AssociateRoleKeyReference + */ + protected function mapper() + { + return function (?int $index): ?AssociateRoleKeyReference { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var AssociateRoleKeyReference $data */ + $data = AssociateRoleKeyReferenceModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReferenceModel.php b/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReferenceModel.php new file mode 100644 index 00000000000..a085be06d1f --- /dev/null +++ b/lib/commercetools-import/src/Models/Common/AssociateRoleKeyReferenceModel.php @@ -0,0 +1,95 @@ +key = $key; + $this->typeId = $typeId ?? self::DISCRIMINATOR_VALUE; + } + + /** + *

User-defined unique identifier of the referenced Type.

+ * + * + * @return null|string + */ + public function getKey() + { + if (is_null($this->key)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_KEY); + if (is_null($data)) { + return null; + } + $this->key = (string) $data; + } + + return $this->key; + } + + /** + *

Type of referenced resource.

+ * + * + * @return null|string + */ + public function getTypeId() + { + if (is_null($this->typeId)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE_ID); + if (is_null($data)) { + return null; + } + $this->typeId = (string) $data; + } + + return $this->typeId; + } + + + /** + * @param ?string $key + */ + public function setKey(?string $key): void + { + $this->key = $key; + } +} diff --git a/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReference.php b/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReference.php new file mode 100644 index 00000000000..56803db806d --- /dev/null +++ b/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReference.php @@ -0,0 +1,28 @@ +User-defined unique identifier of the referenced Type.

+ * + + * @return null|string + */ + public function getKey(); + + /** + * @param ?string $key + */ + public function setKey(?string $key): void; +} diff --git a/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReferenceBuilder.php b/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReferenceBuilder.php new file mode 100644 index 00000000000..e7238108be9 --- /dev/null +++ b/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReferenceBuilder.php @@ -0,0 +1,63 @@ + + */ +final class BusinessUnitKeyReferenceBuilder implements Builder +{ + /** + + * @var ?string + */ + private $key; + + /** + *

User-defined unique identifier of the referenced Type.

+ * + + * @return null|string + */ + public function getKey() + { + return $this->key; + } + + /** + * @param ?string $key + * @return $this + */ + public function withKey(?string $key) + { + $this->key = $key; + + return $this; + } + + + public function build(): BusinessUnitKeyReference + { + return new BusinessUnitKeyReferenceModel( + $this->key + ); + } + + public static function of(): BusinessUnitKeyReferenceBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReferenceCollection.php b/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReferenceCollection.php new file mode 100644 index 00000000000..e944c8b68e7 --- /dev/null +++ b/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReferenceCollection.php @@ -0,0 +1,56 @@ + + * @method BusinessUnitKeyReference current() + * @method BusinessUnitKeyReference end() + * @method BusinessUnitKeyReference at($offset) + */ +class BusinessUnitKeyReferenceCollection extends KeyReferenceCollection +{ + /** + * @psalm-assert BusinessUnitKeyReference $value + * @psalm-param BusinessUnitKeyReference|stdClass $value + * @throws InvalidArgumentException + * + * @return BusinessUnitKeyReferenceCollection + */ + public function add($value) + { + if (!$value instanceof BusinessUnitKeyReference) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?BusinessUnitKeyReference + */ + protected function mapper() + { + return function (?int $index): ?BusinessUnitKeyReference { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var BusinessUnitKeyReference $data */ + $data = BusinessUnitKeyReferenceModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReferenceModel.php b/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReferenceModel.php new file mode 100644 index 00000000000..7f25751c1bc --- /dev/null +++ b/lib/commercetools-import/src/Models/Common/BusinessUnitKeyReferenceModel.php @@ -0,0 +1,95 @@ +key = $key; + $this->typeId = $typeId ?? self::DISCRIMINATOR_VALUE; + } + + /** + *

User-defined unique identifier of the referenced Type.

+ * + * + * @return null|string + */ + public function getKey() + { + if (is_null($this->key)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_KEY); + if (is_null($data)) { + return null; + } + $this->key = (string) $data; + } + + return $this->key; + } + + /** + *

Type of referenced resource.

+ * + * + * @return null|string + */ + public function getTypeId() + { + if (is_null($this->typeId)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE_ID); + if (is_null($data)) { + return null; + } + $this->typeId = (string) $data; + } + + return $this->typeId; + } + + + /** + * @param ?string $key + */ + public function setKey(?string $key): void + { + $this->key = $key; + } +} diff --git a/lib/commercetools-import/src/Models/Common/KeyReferenceModel.php b/lib/commercetools-import/src/Models/Common/KeyReferenceModel.php index faa4ad2cc87..8e352223b91 100644 --- a/lib/commercetools-import/src/Models/Common/KeyReferenceModel.php +++ b/lib/commercetools-import/src/Models/Common/KeyReferenceModel.php @@ -37,6 +37,8 @@ final class KeyReferenceModel extends JsonObjectModel implements KeyReference * */ private static $discriminatorClasses = [ + 'associate-role' => AssociateRoleKeyReferenceModel::class, + 'business-unit' => BusinessUnitKeyReferenceModel::class, 'cart' => CartKeyReferenceModel::class, 'cart-discount' => CartDiscountKeyReferenceModel::class, 'category' => CategoryKeyReferenceModel::class, diff --git a/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequest.php b/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequest.php new file mode 100644 index 00000000000..2362c9fbe10 --- /dev/null +++ b/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequest.php @@ -0,0 +1,31 @@ +The Business Unit import resources of this request. Can contain CompanyBusinessUnitImport or DivisionBusinessUnitImport.

+ * + + * @return null|BusinessUnitImportCollection + */ + public function getResources(); + + /** + * @param ?BusinessUnitImportCollection $resources + */ + public function setResources(?BusinessUnitImportCollection $resources): void; +} diff --git a/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequestBuilder.php b/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequestBuilder.php new file mode 100644 index 00000000000..a83a0f078f6 --- /dev/null +++ b/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequestBuilder.php @@ -0,0 +1,64 @@ + + */ +final class BusinessUnitImportRequestBuilder implements Builder +{ + /** + + * @var ?BusinessUnitImportCollection + */ + private $resources; + + /** + *

The Business Unit import resources of this request. Can contain CompanyBusinessUnitImport or DivisionBusinessUnitImport.

+ * + + * @return null|BusinessUnitImportCollection + */ + public function getResources() + { + return $this->resources; + } + + /** + * @param ?BusinessUnitImportCollection $resources + * @return $this + */ + public function withResources(?BusinessUnitImportCollection $resources) + { + $this->resources = $resources; + + return $this; + } + + + public function build(): BusinessUnitImportRequest + { + return new BusinessUnitImportRequestModel( + $this->resources + ); + } + + public static function of(): BusinessUnitImportRequestBuilder + { + return new self(); + } +} diff --git a/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequestCollection.php b/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequestCollection.php new file mode 100644 index 00000000000..60e6023fdd3 --- /dev/null +++ b/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequestCollection.php @@ -0,0 +1,56 @@ + + * @method BusinessUnitImportRequest current() + * @method BusinessUnitImportRequest end() + * @method BusinessUnitImportRequest at($offset) + */ +class BusinessUnitImportRequestCollection extends ImportRequestCollection +{ + /** + * @psalm-assert BusinessUnitImportRequest $value + * @psalm-param BusinessUnitImportRequest|stdClass $value + * @throws InvalidArgumentException + * + * @return BusinessUnitImportRequestCollection + */ + public function add($value) + { + if (!$value instanceof BusinessUnitImportRequest) { + throw new InvalidArgumentException(); + } + $this->store($value); + + return $this; + } + + /** + * @psalm-return callable(int):?BusinessUnitImportRequest + */ + protected function mapper() + { + return function (?int $index): ?BusinessUnitImportRequest { + $data = $this->get($index); + if ($data instanceof stdClass) { + /** @var BusinessUnitImportRequest $data */ + $data = BusinessUnitImportRequestModel::of($data); + $this->set($data, $index); + } + + return $data; + }; + } +} diff --git a/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequestModel.php new file mode 100644 index 00000000000..c648b8d56c9 --- /dev/null +++ b/lib/commercetools-import/src/Models/Importrequests/BusinessUnitImportRequestModel.php @@ -0,0 +1,96 @@ +resources = $resources; + $this->type = $type ?? self::DISCRIMINATOR_VALUE; + } + + /** + *

The resource type that can be imported.

+ * + * + * @return null|string + */ + public function getType() + { + if (is_null($this->type)) { + /** @psalm-var ?string $data */ + $data = $this->raw(self::FIELD_TYPE); + if (is_null($data)) { + return null; + } + $this->type = (string) $data; + } + + return $this->type; + } + + /** + *

The Business Unit import resources of this request. Can contain CompanyBusinessUnitImport or DivisionBusinessUnitImport.

+ * + * + * @return null|BusinessUnitImportCollection + */ + public function getResources() + { + if (is_null($this->resources)) { + /** @psalm-var ?list $data */ + $data = $this->raw(self::FIELD_RESOURCES); + if (is_null($data)) { + return null; + } + $this->resources = BusinessUnitImportCollection::fromArray($data); + } + + return $this->resources; + } + + + /** + * @param ?BusinessUnitImportCollection $resources + */ + public function setResources(?BusinessUnitImportCollection $resources): void + { + $this->resources = $resources; + } +} diff --git a/lib/commercetools-import/src/Models/Importrequests/CategoryImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/CategoryImportRequestModel.php index 0f0e7263f9f..5e857d53f72 100644 --- a/lib/commercetools-import/src/Models/Importrequests/CategoryImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/CategoryImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/CustomerImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/CustomerImportRequestModel.php index 6af2fed969b..4340c11cad3 100644 --- a/lib/commercetools-import/src/Models/Importrequests/CustomerImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/CustomerImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/DiscountCodeImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/DiscountCodeImportRequestModel.php index 1c7b4589e58..033c0bfa767 100644 --- a/lib/commercetools-import/src/Models/Importrequests/DiscountCodeImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/DiscountCodeImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/ImportRequest.php b/lib/commercetools-import/src/Models/Importrequests/ImportRequest.php index 55b68da6334..a608500be13 100644 --- a/lib/commercetools-import/src/Models/Importrequests/ImportRequest.php +++ b/lib/commercetools-import/src/Models/Importrequests/ImportRequest.php @@ -17,7 +17,7 @@ interface ImportRequest extends JsonObject public const FIELD_TYPE = 'type'; /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/ImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/ImportRequestModel.php index 91601cd3e30..0c5edf62a5b 100644 --- a/lib/commercetools-import/src/Models/Importrequests/ImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/ImportRequestModel.php @@ -31,6 +31,7 @@ final class ImportRequestModel extends JsonObjectModel implements ImportRequest * */ private static $discriminatorClasses = [ + 'business-unit' => BusinessUnitImportRequestModel::class, 'category' => CategoryImportRequestModel::class, 'customer' => CustomerImportRequestModel::class, 'discount-code' => DiscountCodeImportRequestModel::class, @@ -58,7 +59,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/InventoryImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/InventoryImportRequestModel.php index 7470eb4b793..6542d203253 100644 --- a/lib/commercetools-import/src/Models/Importrequests/InventoryImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/InventoryImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/OrderImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/OrderImportRequestModel.php index 098092f9773..32387d93d7a 100644 --- a/lib/commercetools-import/src/Models/Importrequests/OrderImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/OrderImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/OrderPatchImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/OrderPatchImportRequestModel.php index 86f2e065c56..53f9ffa0885 100644 --- a/lib/commercetools-import/src/Models/Importrequests/OrderPatchImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/OrderPatchImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/PriceImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/PriceImportRequestModel.php index 22fc9359c97..e325ec6c816 100644 --- a/lib/commercetools-import/src/Models/Importrequests/PriceImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/PriceImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/ProductDraftImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/ProductDraftImportRequestModel.php index 1907cecefb7..0a6e5c73659 100644 --- a/lib/commercetools-import/src/Models/Importrequests/ProductDraftImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/ProductDraftImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/ProductImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/ProductImportRequestModel.php index f68d03e58bf..fbcf0c5248b 100644 --- a/lib/commercetools-import/src/Models/Importrequests/ProductImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/ProductImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/ProductSelectionImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/ProductSelectionImportRequestModel.php index 4a56f9dd5c9..d3377110ec0 100644 --- a/lib/commercetools-import/src/Models/Importrequests/ProductSelectionImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/ProductSelectionImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/ProductTypeImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/ProductTypeImportRequestModel.php index 26e1ee42678..e0fce4590d7 100644 --- a/lib/commercetools-import/src/Models/Importrequests/ProductTypeImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/ProductTypeImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/ProductVariantImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/ProductVariantImportRequestModel.php index 25e8b121f53..bf4d1d4b974 100644 --- a/lib/commercetools-import/src/Models/Importrequests/ProductVariantImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/ProductVariantImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/ProductVariantPatchRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/ProductVariantPatchRequestModel.php index a0f997b03b5..7e7ef8825d9 100644 --- a/lib/commercetools-import/src/Models/Importrequests/ProductVariantPatchRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/ProductVariantPatchRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/StandalonePriceImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/StandalonePriceImportRequestModel.php index 433710d51f6..9c8699ce9bf 100644 --- a/lib/commercetools-import/src/Models/Importrequests/StandalonePriceImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/StandalonePriceImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/lib/commercetools-import/src/Models/Importrequests/TypeImportRequestModel.php b/lib/commercetools-import/src/Models/Importrequests/TypeImportRequestModel.php index 4c8fde2882c..e4ccebf2407 100644 --- a/lib/commercetools-import/src/Models/Importrequests/TypeImportRequestModel.php +++ b/lib/commercetools-import/src/Models/Importrequests/TypeImportRequestModel.php @@ -46,7 +46,7 @@ public function __construct( } /** - *

The resource types that can be imported.

+ *

The resource type that can be imported.

* * * @return null|string diff --git a/references.txt b/references.txt index 893d29a1c4c..23627f49e52 100644 --- a/references.txt +++ b/references.txt @@ -490,3 +490,4 @@ d084ab15a8dfa7bd18efa10417a0bb263c08f269 4b73acb69ed586da4ca2893e3b698335c356d720 cb9cca64ecfb31885e7b9fb0ad52a9954b990ed9 48dc5d57bbfede103bdf01023deea4f649dc5cae +291e2569b7c0e4f1db3bb99761c7b23e0cc1659f