Skip to content

Commit

Permalink
[shopsys] list of complaints in personal data (#3433)
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmannmartin authored Nov 11, 2024
2 parents 394e656 + 7053ac8 commit 695ad69
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Controller/Front/PersonalDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -32,6 +34,7 @@ public function __construct(
protected readonly NewsletterFacade $newsletterFacade,
protected readonly PersonalDataAccessRequestFacade $personalDataAccessRequestFacade,
protected readonly XmlResponse $xmlResponse,
protected readonly ComplaintFacade $complaintFacade,
) {
}

Expand Down Expand Up @@ -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';
Expand Down
7 changes: 6 additions & 1 deletion src/Model/Complaint/Complaint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/Model/Complaint/ComplaintData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class ComplaintData
*/
public $number;

/**
* @var \DateTime|null
*/
public $createdAt;

/**
* @var \Shopsys\FrameworkBundle\Model\Order\Order|null
*/
Expand Down
15 changes: 15 additions & 0 deletions src/Model/Complaint/ComplaintFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/Model/Complaint/ComplaintRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
}
}
39 changes: 39 additions & 0 deletions src/Resources/views/Front/Content/PersonalData/complaints.xml.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<customer_complaints>
{# @var complaints \Shopsys\FrameworkBundle\Model\Complaint\Complaint[] #}
{% for complaint in complaints %}
<complaint>
<complaint_number>{{ complaint.number }}</complaint_number>
<complaint_create_date>{{ complaint.createdAt|date('c') }}</complaint_create_date>
<complaint_addresses>
<address>
<firstname><![CDATA[{{ complaint.deliveryFirstName }}]]></firstname>
<lastname><![CDATA[{{ complaint.deliveryLastName }}]]></lastname>
<company_name><![CDATA[{{ complaint.deliveryCompanyName }}]]></company_name>
<street><![CDATA[{{ complaint.deliveryStreet }}]]></street>
<city><![CDATA[{{ complaint.deliveryCity }}]]></city>
<postal_code><![CDATA[{{ complaint.deliveryPostcode }}]]></postal_code>
<telephone><![CDATA[{{ complaint.deliveryTelephone }}]]></telephone>
{% if complaint.deliveryCountry is not null %}
<country_code><![CDATA[{{ complaint.deliveryCountry.code }}]]></country_code>
{% endif %}
</address>
</complaint_addresses>

<complaint_items>
{% for item in complaint.items %}
{# @var item \Shopsys\FrameworkBundle\Model\Complaint\ComplaintItem #}
<item>
<item_name><![CDATA[{{ item.productName }}]]></item_name>
<item_quantity>{{ item.quantity }}</item_quantity>
<item_catnum><![CDATA[{{ item.catnum }}]]></item_catnum>
<item_description><![CDATA[{{ item.description }}]]></item_description>
</item>
{% endfor %}
</complaint_items>

<complaint_other_data>
<complaint_status>{{ complaint.status.name }}</complaint_status>
</complaint_other_data>
</complaint>
{% endfor %}
</customer_complaints>
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

</customer>
</customers>

0 comments on commit 695ad69

Please sign in to comment.