diff --git a/app/DoctrineMigrations/Version20251112150807.php b/app/DoctrineMigrations/Version20251112150807.php new file mode 100644 index 0000000000..e6d2b606a0 --- /dev/null +++ b/app/DoctrineMigrations/Version20251112150807.php @@ -0,0 +1,26 @@ +addSql('ALTER TABLE address ADD deleted_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE address DROP deleted_at'); + } +} diff --git a/config/packages/fos_js_routing.yaml b/config/packages/fos_js_routing.yaml index 9e513cd425..0f29214ab0 100644 --- a/config/packages/fos_js_routing.yaml +++ b/config/packages/fos_js_routing.yaml @@ -105,3 +105,4 @@ fos_js_routing: - task_label_pdf - _api_/stores/{id}/deliveries_get_collection - _api_/deliveries/pod_export_post + - _api_/addresses/{id}{._format}_delete diff --git a/src/Controller/ProfileController.php b/src/Controller/ProfileController.php index c8300d05a7..926ff1639f 100644 --- a/src/Controller/ProfileController.php +++ b/src/Controller/ProfileController.php @@ -251,9 +251,9 @@ public function orderAction($id, Request $request, #[Route(path: '/profile/addresses', name: 'profile_addresses')] public function addressesAction(Request $request) { - return $this->render('profile/addresses.html.twig', array( + return $this->render('profile/addresses.html.twig', $this->auth([ 'addresses' => $this->getUser()->getAddresses(), - )); + ])); } #[Route(path: '/profile/addresses/new', name: 'profile_address_new')] diff --git a/src/Entity/Address.php b/src/Entity/Address.php index e9715ee0dc..5b214e0dd8 100644 --- a/src/Entity/Address.php +++ b/src/Entity/Address.php @@ -2,6 +2,7 @@ namespace AppBundle\Entity; +use ApiPlatform\Metadata\Delete; use ApiPlatform\Metadata\Link; use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\GetCollection; @@ -11,12 +12,15 @@ use ApiPlatform\Metadata\ApiProperty; use ApiPlatform\Metadata\ApiFilter; use AppBundle\Action\CreateAddress; +use AppBundle\Action\DeleteAddress; use AppBundle\Api\State\StoreAddressesProvider; use AppBundle\Entity\Base\BaseAddress; use AppBundle\Entity\Base\GeoCoordinates; use AppBundle\Entity\Store; use Symfony\Component\Serializer\Annotation\Groups; use Symfony\Component\Serializer\Annotation\SerializedName; +use Gedmo\SoftDeleteable\SoftDeleteable as SoftDeleteableInterface; +use Gedmo\SoftDeleteable\Traits\SoftDeleteable; /** * @see http://schema.org/Place Documentation on Schema.org @@ -26,6 +30,7 @@ operations: [ new Get(security: 'is_granted(\'ROLE_ADMIN\')'), new Patch(security: 'is_granted(\'edit\', object)'), + new Delete(security: 'is_granted(\'edit\', object)'), new GetCollection(security: 'is_granted(\'ROLE_ADMIN\')'), new Post(uriTemplate: '/me/addresses', controller: CreateAddress::class) ], @@ -42,8 +47,9 @@ normalizationContext: ['groups' => ['address']], provider: StoreAddressesProvider::class )] -class Address extends BaseAddress +class Address extends BaseAddress implements SoftDeleteableInterface { + use SoftDeleteable; const PROVIDER_MAPPICKER = 'MAP_PICKER'; const PROVIDERS = [ diff --git a/src/Entity/Sylius/Customer.php b/src/Entity/Sylius/Customer.php index 95d335d945..6df7c288f3 100644 --- a/src/Entity/Sylius/Customer.php +++ b/src/Entity/Sylius/Customer.php @@ -131,7 +131,9 @@ public function hasAddress(Address $address): bool */ public function getAddresses(): Collection { - return $this->addresses; + return $this->addresses->filter(function (Address $address) { + return !$address->isDeleted(); + }); } /** diff --git a/src/Resources/config/doctrine/Address.orm.xml b/src/Resources/config/doctrine/Address.orm.xml index c9eb9c6c1e..d85b1996bf 100644 --- a/src/Resources/config/doctrine/Address.orm.xml +++ b/src/Resources/config/doctrine/Address.orm.xml @@ -1,7 +1,9 @@ + xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd" + xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping" +> @@ -26,6 +28,8 @@ + + diff --git a/templates/profile/addresses.html.twig b/templates/profile/addresses.html.twig index f4d8ed9ce0..f794dae384 100644 --- a/templates/profile/addresses.html.twig +++ b/templates/profile/addresses.html.twig @@ -15,6 +15,15 @@ {{ address.streetAddress }} {{ address.name }} + + + + {% endfor %}