Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/DoctrineMigrations/Version20251112150807.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20251112150807 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add deleted_at to address to soft delete';
}

public function up(Schema $schema): void
{
$this->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');
}
}
1 change: 1 addition & 0 deletions config/packages/fos_js_routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down
8 changes: 7 additions & 1 deletion src/Entity/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AppBundle\Entity;

use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
Expand All @@ -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
Expand All @@ -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)
],
Expand All @@ -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 = [
Expand Down
4 changes: 3 additions & 1 deletion src/Entity/Sylius/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Resources/config/doctrine/Address.orm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
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"
>
<entity name="AppBundle\Entity\Address" table="address">
<indexes>
<index name="idx_address_geo" columns="geo" flags="spatial" />
Expand All @@ -26,6 +28,8 @@
<field name="telephone" type="phone_number" column="telephone" nullable="true" />
<field name="contactName" type="string" column="contact_name" nullable="true" />
<field name="provider" type="string" column="provider" nullable="true" />
<field name="deletedAt" type="datetime" column="deleted_at" nullable="true" />
<gedmo:soft-deleteable field-name="deletedAt" time-aware="false" hard-delete="false" />
<entity-listeners>
<entity-listener class="AppBundle\Entity\Listener\AddressListener">
<lifecycle-callback type="preUpdate" method="preUpdate" />
Expand Down
9 changes: 9 additions & 0 deletions templates/profile/addresses.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
<tr>
<td>{{ address.streetAddress }}</td>
<td class="text-right">{{ address.name }}</td>
<td class="text-right">
<span {{ react_component('DeleteIcon', {
objectId: address.id,
objectName: address.streetAddress,
deleteUrl: '_api_/addresses/{id}{._format}_delete',
errorMessage: 'ADMIN_PLEASE_UNLINK_PRICING_RULE_SET_BEFORE_DELETION'
}) }}>
</span>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
Loading