|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
-
- namespace Lc\CaracoleBundle\Builder\Address;
-
- use App\Entity\Address\Address;
- use App\Repository\Order\OrderShopStore;
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Repository\File\DocumentStore;
-
- class AddressBuilder
- {
- protected EntityManagerInterface $entityManager;
- protected OrderShopStore $orderShopStore;
- protected DocumentStore $documentStore;
-
- public function __construct(
- EntityManagerInterface $entityManager,
- OrderShopStore $orderShopStore,
- DocumentStore $documentStore
- ) {
- $this->entityManager = $entityManager;
- $this->orderShopStore = $orderShopStore;
- $this->documentStore = $documentStore;
- }
-
- // unlinkAddress
- public function unlink(Address $address): void
- {
- $orderShops = $this->orderShopStore->getBy(
- [
- 'address' => $address
- ]
- );
-
- if ($orderShops) {
- foreach ($orderShops as $orderShop) {
- $update = false;
- if ($orderShop->getInvoiceAddress() == $address) {
- $orderShop->setInvoiceAddress(null);
- $update = true;
- }
- if ($orderShop->getDeliveryAddress() == $address) {
- $orderShop->setDeliveryAddress(null);
- $update = true;
- }
- if ($update) {
- $this->entityManager->update($orderShop);
- }
- }
- }
-
- $documents = $this->documentStore->getByBuyerAddress($address);
-
- if ($documents) {
- foreach ($documents as $document) {
- $update = false;
- if ($document->getBuyerAddress() == $address) {
- $document->setBuyerAddress(null);
- $update = true;
- }
- if ($update) {
- $this->entityManager->update($document);
- }
- }
- }
-
- $this->entityManager->flush();
- }
- }
|