-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/EventSubscriber/RemoveCartBeforeExportCustomerSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Synolia\SyliusGDPRPlugin\EventSubscriber; | ||
|
||
use Sylius\Component\Core\Model\OrderInterface as CoreOrderInterface; | ||
use Sylius\Component\Core\Repository\OrderRepositoryInterface; | ||
use Sylius\Component\Order\Model\OrderInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Synolia\SyliusGDPRPlugin\Event\BeforeExportCustomerData; | ||
|
||
class RemoveCartBeforeExportCustomerSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private OrderRepositoryInterface $orderRepository, | ||
) { | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
BeforeExportCustomerData::class => ['process'], | ||
]; | ||
} | ||
|
||
public function process(BeforeExportCustomerData $beforeExportCustomerData): void | ||
{ | ||
$carts = $this->orderRepository->findBy([ | ||
'customer' => $beforeExportCustomerData->getCustomer(), | ||
'state' => OrderInterface::STATE_CART, | ||
]); | ||
|
||
/** @var CoreOrderInterface $cart */ | ||
foreach ($carts as $cart) { | ||
$this->orderRepository->remove($cart); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Synolia\SyliusGDPRPlugin\PHPUnit\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
|
||
class ExportDataControllerTest extends WebTestCase | ||
{ | ||
public function testExportDataWithCart(): void | ||
{ | ||
$client = static::createClient(); | ||
|
||
// login a user | ||
$shopUser = static::getContainer()->get('sylius.repository.shop_user')->findOneBy([]); | ||
$client->loginUser($shopUser); | ||
|
||
// go to product page | ||
$client->request('GET', '/en_US/products/sport-basic-white-t-shirt'); | ||
$this->assertSelectorTextContains('h1', 'Sport basic white T-Shirt'); | ||
|
||
// add product to cart | ||
$client->submitForm('Add to cart'); | ||
$client->request('GET', '/en_US/cart/'); | ||
$this->assertSelectorTextContains('h1', 'Your shopping cart'); | ||
|
||
// login as admin and go to customer page | ||
$adminUser = static::getContainer()->get('sylius.repository.admin_user')->findOneBy([]); | ||
$client->loginUser($adminUser, 'admin'); | ||
$client->request('GET', sprintf('/admin/customers/%s', $shopUser->getId())); | ||
|
||
// export data for this user | ||
$client->clickLink('Export data'); | ||
$this->assertResponseIsSuccessful(); | ||
} | ||
} |