generated from Setono/SyliusPluginSkeleton
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Setono/fix-possible-orm-exception
Change the way notifications are created and associated with an order/cart
- Loading branch information
Showing
6 changed files
with
59 additions
and
39 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/EventListener/Doctrine/CreateNotificationOnOrderPersistenceListener.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 Setono\SyliusAbandonedCartPlugin\EventListener\Doctrine; | ||
|
||
use Doctrine\Persistence\Event\LifecycleEventArgs; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use Setono\DoctrineObjectManagerTrait\ORM\ORMManagerTrait; | ||
use Setono\SyliusAbandonedCartPlugin\Factory\NotificationFactoryInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
|
||
final class CreateNotificationOnOrderPersistenceListener | ||
{ | ||
use ORMManagerTrait; | ||
|
||
private NotificationFactoryInterface $notificationFactory; | ||
|
||
public function __construct( | ||
NotificationFactoryInterface $notificationFactory, | ||
ManagerRegistry $managerRegistry | ||
) { | ||
$this->notificationFactory = $notificationFactory; | ||
$this->managerRegistry = $managerRegistry; | ||
} | ||
|
||
public function prePersist(LifecycleEventArgs $eventArgs): void | ||
{ | ||
$obj = $eventArgs->getObject(); | ||
if (!$obj instanceof OrderInterface) { | ||
return; | ||
} | ||
|
||
$notification = $this->notificationFactory->createWithCart($obj); | ||
|
||
$manager = $this->getManager($notification); | ||
$manager->persist($notification); | ||
} | ||
} |
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
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
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,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<container xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://symfony.com/schema/dic/services" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
<services> | ||
<service id="setono_sylius_abandoned_cart.event_listener.doctrine.create_notification_on_order_persistence" | ||
class="Setono\SyliusAbandonedCartPlugin\EventListener\Doctrine\CreateNotificationOnOrderPersistenceListener"> | ||
<argument type="service" id="setono_sylius_abandoned_cart.factory.notification"/> | ||
<argument type="service" id="doctrine"/> | ||
|
||
<tag name="doctrine.event_listener" event="prePersist"/> | ||
</service> | ||
</services> | ||
</container> |
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
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