選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

AddressBuilder.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Lc\CaracoleBundle\Builder\Address;
  3. use App\Entity\Address\Address;
  4. use App\Repository\Order\OrderShopStore;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Lc\CaracoleBundle\Repository\File\DocumentStore;
  7. class AddressBuilder
  8. {
  9. protected EntityManagerInterface $entityManager;
  10. protected OrderShopStore $orderShopStore;
  11. protected DocumentStore $documentStore;
  12. public function __construct(
  13. EntityManagerInterface $entityManager,
  14. OrderShopStore $orderShopStore,
  15. DocumentStore $documentStore
  16. ) {
  17. $this->entityManager = $entityManager;
  18. $this->orderShopStore = $orderShopStore;
  19. $this->documentStore = $documentStore;
  20. }
  21. // unlinkAddress
  22. public function unlink(Address $address): void
  23. {
  24. $orderShops = $this->orderShopStore->getBy(
  25. [
  26. 'address' => $address
  27. ]
  28. );
  29. if ($orderShops) {
  30. foreach ($orderShops as $orderShop) {
  31. $update = false;
  32. if ($orderShop->getInvoiceAddress() == $address) {
  33. $orderShop->setInvoiceAddress(null);
  34. $update = true;
  35. }
  36. if ($orderShop->getDeliveryAddress() == $address) {
  37. $orderShop->setDeliveryAddress(null);
  38. $update = true;
  39. }
  40. if ($update) {
  41. $this->entityManager->update($orderShop);
  42. }
  43. }
  44. }
  45. $documents = $this->documentStore->getByBuyerAddress($address);
  46. if ($documents) {
  47. foreach ($documents as $document) {
  48. $update = false;
  49. if ($document->getBuyerAddress() == $address) {
  50. $document->setBuyerAddress(null);
  51. $update = true;
  52. }
  53. if ($update) {
  54. $this->entityManager->update($document);
  55. }
  56. }
  57. }
  58. $this->entityManager->flush();
  59. }
  60. }