diff --git a/composer.json b/composer.json index 186a8b7f25..95dfc1f9b2 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "ext-intl": "*", "ext-json": "*", "ext-simplexml": "*", - "api-platform/core": "^3.2.2", + "api-platform/core": "~3.2.2", "babdev/pagerfanta-bundle": "^3.0", "behat/transliterator": "^1.3", "doctrine/collections": "^1.6", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5a114291e6..4d253a07ea 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -595,41 +595,6 @@ parameters: count: 1 path: src/Sylius/Bundle/ApiBundle/Converter/IriToIdentifierConverterInterface.php - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:persist\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php - - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:persist\\(\\) has parameter \\$data with no type specified\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php - - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:remove\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php - - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:remove\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php - - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:remove\\(\\) has parameter \\$data with no type specified\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php - - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:supports\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php - - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AddressDataPersister\\:\\:supports\\(\\) has parameter \\$data with no type specified\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/DataPersister/AddressDataPersister.php - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\DataPersister\\\\AdminUserDataPersister\\:\\:persist\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" count: 1 @@ -1505,11 +1470,6 @@ parameters: count: 1 path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryCollectionExtension/AcceptedProductReviewsExtension.php - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryCollectionExtension\\\\AddressesExtension\\:\\:applyToCollection\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryCollectionExtension/AddressesExtension.php - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryCollectionExtension\\\\AvailableProductAssociationsInProductCollectionExtension\\:\\:applyToCollection\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" count: 1 @@ -1600,21 +1560,6 @@ parameters: count: 1 path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryExtension/ExchangeRateExtension.php - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryItemExtension\\\\AddressItemExtension\\:\\:applyToItem\\(\\) has no return type specified\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryItemExtension/AddressItemExtension.php - - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryItemExtension\\\\AddressItemExtension\\:\\:applyToItem\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryItemExtension/AddressItemExtension.php - - - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryItemExtension\\\\AddressItemExtension\\:\\:applyToItem\\(\\) has parameter \\$identifiers with no value type specified in iterable type array\\.$#" - count: 1 - path: src/Sylius/Bundle/ApiBundle/Doctrine/QueryItemExtension/AddressItemExtension.php - - message: "#^Method Sylius\\\\Bundle\\\\ApiBundle\\\\Doctrine\\\\QueryItemExtension\\\\EnabledProductInProductAssociationItemExtension\\:\\:applyToItem\\(\\) has no return type specified\\.$#" count: 1 diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/Address.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/Address.xml index 28d51232af..892a3d8f40 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/Address.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/Address.xml @@ -15,7 +15,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0 https://api-platform.com/schema/metadata/properties-3.0.xsd" > - + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/AddressLogEntry.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/AddressLogEntry.xml new file mode 100644 index 0000000000..d53f06fe7a --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/properties/AddressLogEntry.xml @@ -0,0 +1,19 @@ + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Address.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Address.xml index c0142de9e0..bba081cc2d 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Address.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/Address.xml @@ -28,9 +28,43 @@ + + + + + + sylius:admin:address:show + + + + + + + + + + + + sylius:admin:address:update + + + + + + + + + sylius:admin:address:show + + + + + + @@ -45,7 +79,8 @@ @@ -59,12 +94,11 @@ - - @@ -88,7 +122,8 @@ @@ -111,67 +146,10 @@ - - - - - sylius:admin:address:show - - - - - - - - - - - - sylius:admin:address:log_entry:show - - - - - - - Get address log entries - Get address log entries - - - - - - - - - - - sylius:admin:address:update - - - - - - - - - sylius:admin:address:show - - - - - + class="ApiPlatform\Metadata\Delete" + uriTemplate="/shop/addresses/{id}" + security="is_granted('SYLIUS_CUSTOMER')" + /> diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/AddressLogEntry.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/AddressLogEntry.xml new file mode 100644 index 0000000000..4225df396b --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/api_platform/resources/AddressLogEntry.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + objectId + + + + + + + + + + + sylius:admin:address:log_entry:show + + + + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/app/config.yaml b/src/Sylius/Bundle/ApiBundle/Resources/config/app/config.yaml index f1bec76155..01784aba68 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/app/config.yaml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/app/config.yaml @@ -10,6 +10,7 @@ parameters: sylius.api.doctrine_extension.order_visitor_item.filter_cart.allowed_non_get_operations: - "shop_select_payment_method" sylius.api.paths_to_hide: + - "%sylius.security.new_api_route%/admin/address-log-entry/{id}" - "%sylius.security.new_api_route%/admin/catalog-promotion-actions/{id}" - "%sylius.security.new_api_route%/admin/catalog-promotion-scopes/{id}" - "%sylius.security.new_api_route%/admin/channel-pricings/{id}" diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/Address.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/Address.xml deleted file mode 100644 index 960b6d1761..0000000000 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/legacy_api_resources/Address.xml +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - sylius - - - - GET - /shop/addresses - - - shop:address:index - sylius:shop:address:index - - - - - - POST - /shop/addresses - - - shop:address:create - sylius:shop:address:create - - - - - shop:address:show - sylius:shop:address:show - - - - - - - - GET - /admin/addresses/{id} - - - admin:address:show - sylius:admin:address:show - - - - - - PUT - /admin/addresses/{id} - - - admin:address:update - sylius:admin:address:update - - - - - admin:address:show - sylius:admin:address:show - - - - - - GET - /admin/addresses/{id}/log-entries - Sylius\Bundle\ApiBundle\Controller\GetAddressLogEntryCollectionAction - - - admin:address:log_entry:show - sylius:admin:address:log_entry:show - - - - Retrieves the collection of AddressLogEntry resources. - Retrieves the collection of AddressLogEntry resources - - - - - GET - /shop/addresses/{id} - - - shop:address:show - sylius:shop:address:show - - - - - - DELETE - /shop/addresses/{id} - - - - PUT - /shop/addresses/{id} - - - shop:address:update - sylius:shop:address:update - - - - - shop:address:show - sylius:shop:address:show - - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/ApiBundle/StateProcessor/Post/AddressProcessor.php b/src/Sylius/Bundle/ApiBundle/StateProcessor/Post/AddressProcessor.php new file mode 100644 index 0000000000..3a7f4fe01d --- /dev/null +++ b/src/Sylius/Bundle/ApiBundle/StateProcessor/Post/AddressProcessor.php @@ -0,0 +1,56 @@ + + */ +final readonly class AddressProcessor implements ProcessorInterface +{ + public function __construct( + private ProcessorInterface $persistProcessor, + private UserContextInterface $userContext, + ) { + } + + /** + * @param AddressInterface $data + */ + public function process($data, Operation $operation, array $uriVariables = [], array $context = []) + { + Assert::isInstanceOf($data, AddressInterface::class); + Assert::isInstanceOf($operation, Post::class); + + $user = $this->userContext->getUser(); + $customer = $user instanceof ShopUserInterface ? $user->getCustomer() : null; + + if (null !== $customer) { + $data->setCustomer($customer); + + if (null === $customer->getDefaultAddress()) { + $customer->setDefaultAddress($data); + } + } + + return $this->persistProcessor->process($data, $operation, $uriVariables, $context); + } +}