-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #12050 Refactor mailing (lchrusciel, SirDomin)
This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | not sure | Related tickets | refactoring the way we handle emails implemented in #11754 | License | MIT <!-- - Bug fixes must be submitted against the 1.7 or 1.8 branch (the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits ------- c0d8f32 [API] Order confirmation email sending 85b296b [Core] Extract mailer sender from ShopBundle a73d321 fix composer.json api platform, tests for api mailing added 24ac912 command added 18818a7 mailing is handled with commands da13fb2 pr fix, behat + spec fixed b10b272 pr-fix 0def0d8 introduce event bus
- Loading branch information
Showing
10 changed files
with
285 additions
and
15 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Sylius/Bundle/ApiBundle/Command/SendOrderConfirmation.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,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ApiBundle\Command; | ||
|
||
/** @experimental */ | ||
class SendOrderConfirmation | ||
{ | ||
/** @var string */ | ||
public $orderToken; | ||
|
||
public function __construct(string $orderToken) | ||
{ | ||
$this->orderToken = $orderToken; | ||
} | ||
|
||
public function orderToken(): string | ||
{ | ||
return $this->orderToken; | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
src/Sylius/Bundle/ApiBundle/CommandHandler/SendOrderConfirmationHandler.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,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ApiBundle\CommandHandler; | ||
|
||
use Sylius\Bundle\ApiBundle\Command\SendOrderConfirmation; | ||
use Sylius\Bundle\CoreBundle\Mailer\Emails; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Repository\OrderRepositoryInterface; | ||
use Sylius\Component\Mailer\Sender\SenderInterface; | ||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; | ||
|
||
/** @experimental */ | ||
final class SendOrderConfirmationHandler implements MessageHandlerInterface | ||
{ | ||
/** @var SenderInterface */ | ||
private $emailSender; | ||
|
||
/** @var OrderRepositoryInterface */ | ||
private $orderRepository; | ||
|
||
public function __construct(SenderInterface $emailSender, OrderRepositoryInterface $orderRepository) | ||
{ | ||
$this->emailSender = $emailSender; | ||
$this->orderRepository = $orderRepository; | ||
} | ||
|
||
public function __invoke(SendOrderConfirmation $sendOrderConfirmation): void | ||
{ | ||
/** @var OrderInterface $order */ | ||
$order = $this->orderRepository->findOneByTokenValue($sendOrderConfirmation->orderToken()); | ||
|
||
$this->emailSender->send( | ||
Emails::ORDER_CONFIRMATION_RESENT, | ||
[$order->getCustomer()->getEmail()], | ||
[ | ||
'order' => $order, | ||
'channel' => $order->getChannel(), | ||
'localeCode' => $order->getLocaleCode(), | ||
] | ||
); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ApiBundle\Event; | ||
|
||
class OrderCompleted | ||
{ | ||
/** @var string */ | ||
public $orderToken; | ||
|
||
public function __construct(string $orderToken) | ||
{ | ||
$this->orderToken = $orderToken; | ||
} | ||
|
||
public function orderToken(): string | ||
{ | ||
return $this->orderToken; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Sylius/Bundle/ApiBundle/EventHandler/OrderCompletedHandler.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,35 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ApiBundle\EventHandler; | ||
|
||
use Sylius\Bundle\ApiBundle\Command\SendOrderConfirmation; | ||
use Sylius\Bundle\ApiBundle\Event\OrderCompleted; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
|
||
/** @experimental */ | ||
final class OrderCompletedHandler | ||
{ | ||
/** @var MessageBusInterface */ | ||
private $commandBus; | ||
|
||
public function __construct(MessageBusInterface $commandBus) | ||
{ | ||
$this->commandBus = $commandBus; | ||
} | ||
|
||
public function __invoke(OrderCompleted $orderCompleted): void | ||
{ | ||
$this->commandBus->dispatch(new SendOrderConfirmation($orderCompleted->orderToken())); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/Sylius/Bundle/ApiBundle/Resources/config/services/event_handlers.xml
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,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- | ||
This file is part of the Sylius package. | ||
(c) Paweł Jędrzejewski | ||
For the full copyright and license information, please view the LICENSE | ||
file that was distributed with this source code. | ||
--> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" | ||
> | ||
<services> | ||
<service id="Sylius\Bundle\ApiBundle\EventHandler\OrderCompletedHandler"> | ||
<argument type="service" id="message_bus" /> | ||
<argument type="service" id="sylius.repository.order" /> | ||
<tag name="messenger.message_handler" bus="sylius_event.bus"/> | ||
</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
Oops, something went wrong.