diff --git a/src/Controller/Front/PersonalDataController.php b/src/Controller/Front/PersonalDataController.php index c9913d1e08..06f2d32617 100644 --- a/src/Controller/Front/PersonalDataController.php +++ b/src/Controller/Front/PersonalDataController.php @@ -6,6 +6,7 @@ use Shopsys\FrameworkBundle\Component\Domain\Domain; use Shopsys\FrameworkBundle\Component\HttpFoundation\XmlResponse; +use Shopsys\FrameworkBundle\Model\Complaint\ComplaintFacade; use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUserFacade; use Shopsys\FrameworkBundle\Model\Newsletter\NewsletterFacade; use Shopsys\FrameworkBundle\Model\Order\OrderFacade; @@ -24,6 +25,7 @@ class PersonalDataController extends AbstractController * @param \Shopsys\FrameworkBundle\Model\Newsletter\NewsletterFacade $newsletterFacade * @param \Shopsys\FrameworkBundle\Model\PersonalData\PersonalDataAccessRequestFacade $personalDataAccessRequestFacade * @param \Shopsys\FrameworkBundle\Component\HttpFoundation\XmlResponse $xmlResponse + * @param \Shopsys\FrameworkBundle\Model\Complaint\ComplaintFacade $complaintFacade */ public function __construct( protected readonly Domain $domain, @@ -32,6 +34,7 @@ public function __construct( protected readonly NewsletterFacade $newsletterFacade, protected readonly PersonalDataAccessRequestFacade $personalDataAccessRequestFacade, protected readonly XmlResponse $xmlResponse, + protected readonly ComplaintFacade $complaintFacade, ) { } @@ -65,10 +68,17 @@ public function exportXmlAction(string $hash): Response $this->domain->getId(), ); + $complaints = []; + + if ($customerUser !== null) { + $complaints = $this->complaintFacade->getComplaintsByCustomerUserAndDomainIdAndLocale($customerUser, $this->domain->getId(), $this->domain->getLocale()); + } + $xmlContent = $this->render('@ShopsysFramework/Front/Content/PersonalData/export.xml.twig', [ 'customerUser' => $customerUser, 'newsletterSubscriber' => $newsletterSubscriber, 'orders' => $orders, + 'complaints' => $complaints, ])->getContent(); $fileName = $personalDataAccessRequest->getEmail() . '.xml'; diff --git a/src/Model/Complaint/Complaint.php b/src/Model/Complaint/Complaint.php index 528a68b5b3..5bb55966b4 100644 --- a/src/Model/Complaint/Complaint.php +++ b/src/Model/Complaint/Complaint.php @@ -141,7 +141,12 @@ class Complaint */ public function __construct(ComplaintData $complaintData, array $complaintItems) { - $this->createdAt = new DateTime(); + if ($complaintData->createdAt === null) { + $this->createdAt = new DateTime(); + } else { + $this->createdAt = $complaintData->createdAt; + } + $this->uuid = $complaintData->uuid ?? Uuid::uuid4()->toString(); $this->number = $complaintData->number; $this->domainId = $complaintData->domainId; diff --git a/src/Model/Complaint/ComplaintData.php b/src/Model/Complaint/ComplaintData.php index 3b9dc33fa2..64004333de 100644 --- a/src/Model/Complaint/ComplaintData.php +++ b/src/Model/Complaint/ComplaintData.php @@ -21,6 +21,11 @@ class ComplaintData */ public $number; + /** + * @var \DateTime|null + */ + public $createdAt; + /** * @var \Shopsys\FrameworkBundle\Model\Order\Order|null */ diff --git a/src/Model/Complaint/ComplaintFacade.php b/src/Model/Complaint/ComplaintFacade.php index 78ddf22db6..2a9b3dfacc 100644 --- a/src/Model/Complaint/ComplaintFacade.php +++ b/src/Model/Complaint/ComplaintFacade.php @@ -8,6 +8,7 @@ use Shopsys\FrameworkBundle\Component\CustomerUploadedFile\CustomerUploadedFileFacade; use Shopsys\FrameworkBundle\Model\Complaint\Exception\ComplaintNotFoundException; use Shopsys\FrameworkBundle\Model\Complaint\Mail\ComplaintMailFacade; +use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser; class ComplaintFacade { @@ -58,6 +59,20 @@ public function edit(int $id, ComplaintData $complaintData): void } } + /** + * @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser $customerUser + * @param int $domainId + * @param string $locale + * @return \Shopsys\FrameworkBundle\Model\Complaint\Complaint[] + */ + public function getComplaintsByCustomerUserAndDomainIdAndLocale( + CustomerUser $customerUser, + int $domainId, + string $locale, + ): array { + return $this->complaintRepository->getComplaintsByCustomerUserAndDomainIdAndLocale($customerUser, $domainId, $locale); + } + /** * @param \Shopsys\FrameworkBundle\Model\Complaint\Complaint $complaint * @param \Shopsys\FrameworkBundle\Model\Complaint\ComplaintItemData[] $complaintItemsData diff --git a/src/Model/Complaint/ComplaintRepository.php b/src/Model/Complaint/ComplaintRepository.php index b7f12b37e6..ed8900fe9c 100644 --- a/src/Model/Complaint/ComplaintRepository.php +++ b/src/Model/Complaint/ComplaintRepository.php @@ -9,6 +9,7 @@ use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Shopsys\FrameworkBundle\Model\Customer\BillingAddress; +use Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser; class ComplaintRepository { @@ -80,4 +81,30 @@ public function findById(int $id): ?Complaint { return $this->getComplaintRepository()->find($id); } + + /** + * @param \Shopsys\FrameworkBundle\Model\Customer\User\CustomerUser $customerUser + * @param int $domainId + * @param string $locale + * @return \Shopsys\FrameworkBundle\Model\Complaint\Complaint[] + */ + public function getComplaintsByCustomerUserAndDomainIdAndLocale( + CustomerUser $customerUser, + int $domainId, + string $locale, + ): array { + return $this->getComplaintRepository()->createQueryBuilder('c') + ->addSelect('cdc, cdct, ci, cs, cst') + ->leftJoin('c.deliveryCountry', 'cdc') + ->leftJoin('cdc.translations', 'cdct', Join::WITH, 'cdct.locale = :locale') + ->join('c.items', 'ci') + ->join('c.status', 'cs') + ->join('cs.translations', 'cst', Join::WITH, 'cst.locale = :locale') + ->where('c.customerUser = :customerUser') + ->andWhere('c.domainId = :domainId') + ->setParameter('customerUser', $customerUser) + ->setParameter('domainId', $domainId) + ->setParameter('locale', $locale) + ->getQuery()->getResult(); + } } diff --git a/src/Resources/views/Front/Content/PersonalData/complaints.xml.twig b/src/Resources/views/Front/Content/PersonalData/complaints.xml.twig new file mode 100644 index 0000000000..52d6dddb4a --- /dev/null +++ b/src/Resources/views/Front/Content/PersonalData/complaints.xml.twig @@ -0,0 +1,39 @@ + + {# @var complaints \Shopsys\FrameworkBundle\Model\Complaint\Complaint[] #} + {% for complaint in complaints %} + + {{ complaint.number }} + {{ complaint.createdAt|date('c') }} + +
+ + + + + + + + {% if complaint.deliveryCountry is not null %} + + {% endif %} +
+
+ + + {% for item in complaint.items %} + {# @var item \Shopsys\FrameworkBundle\Model\Complaint\ComplaintItem #} + + + {{ item.quantity }} + + + + {% endfor %} + + + + {{ complaint.status.name }} + +
+ {% endfor %} +
diff --git a/src/Resources/views/Front/Content/PersonalData/export.xml.twig b/src/Resources/views/Front/Content/PersonalData/export.xml.twig index 82e0a0f256..195150fc24 100644 --- a/src/Resources/views/Front/Content/PersonalData/export.xml.twig +++ b/src/Resources/views/Front/Content/PersonalData/export.xml.twig @@ -39,5 +39,9 @@ {% include('@ShopsysFramework/Front/Content/PersonalData/orders.xml.twig' ) with {'orders': orders} %} {% endif %} + {% if complaints|length > 0 %} + {% include('@ShopsysFramework/Front/Content/PersonalData/complaints.xml.twig') %} + {% endif %} +