-
-
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.
[Admin][Order] Add resending an order confirmation email
- Loading branch information
Showing
17 changed files
with
275 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -20,11 +20,13 @@ Feature: Resending an order confirmation email for a chosen order | |
Scenario: Resending a confirmation email for a given order | ||
When I view the summary of the order "#00000666" | ||
And I resend the order confirmation email | ||
Then an email with the confirmation of the order "#00000666" should be sent to "[email protected]" | ||
Then I should be notified that the order confirmation email has been successfully resent to the customer | ||
And an email with the confirmation of the order "#00000666" should be sent to "[email protected]" | ||
|
||
@ui @email | ||
Scenario: Sending a confirmation email after shipping an order in different locale than the default one | ||
Given the order "#00000666" has been placed in "Polish (Poland)" locale | ||
When I view the summary of the order "#00000666" | ||
And I resend the order confirmation email | ||
Then an email with the confirmation of the order "#00000666" should be sent to "[email protected]" in "Polish (Poland)" locale | ||
Then I should be notified that the order confirmation email has been successfully resent to the customer | ||
And an email with the confirmation of the order "#00000666" should be sent to "[email protected]" in "Polish (Poland)" locale |
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
78 changes: 78 additions & 0 deletions
78
src/Sylius/Bundle/AdminBundle/Action/ResendOrderConfirmationEmailAction.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,78 @@ | ||
<?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\AdminBundle\Action; | ||
|
||
use Sylius\Bundle\AdminBundle\EmailManager\OrderEmailManagerInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Repository\OrderRepositoryInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Session\Session; | ||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\Security\Csrf\CsrfToken; | ||
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface; | ||
|
||
final class ResendOrderConfirmationEmailAction | ||
{ | ||
/** @var OrderRepositoryInterface */ | ||
private $orderRepository; | ||
|
||
/** @var OrderEmailManagerInterface */ | ||
private $orderEmailManager; | ||
|
||
/** @var CsrfTokenManagerInterface */ | ||
private $csrfTokenManager; | ||
|
||
/** @var Session */ | ||
private $session; | ||
|
||
public function __construct( | ||
OrderRepositoryInterface $orderRepository, | ||
OrderEmailManagerInterface $orderEmailManager, | ||
CsrfTokenManagerInterface $csrfTokenManager, | ||
SessionInterface $session | ||
) { | ||
$this->orderRepository = $orderRepository; | ||
$this->orderEmailManager = $orderEmailManager; | ||
$this->csrfTokenManager = $csrfTokenManager; | ||
$this->session = $session; | ||
} | ||
|
||
public function __invoke(Request $request): Response | ||
{ | ||
$orderId = $request->attributes->get('id'); | ||
|
||
if (!$this->csrfTokenManager->isTokenValid(new CsrfToken($orderId, $request->query->get('_csrf_token')))) { | ||
throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid csrf token.'); | ||
} | ||
|
||
/** @var OrderInterface|null $order */ | ||
$order = $this->orderRepository->find($orderId); | ||
if ($order === null) { | ||
throw new NotFoundHttpException(sprintf('The order with id %s has not been found', $orderId)); | ||
} | ||
|
||
$this->orderEmailManager->sendConfirmationEmail($order); | ||
|
||
$this->session->getFlashBag()->add( | ||
'success', | ||
'sylius.email.order_confirmation_resent' | ||
); | ||
|
||
return new RedirectResponse($request->headers->get('referer')); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/Sylius/Bundle/AdminBundle/EmailManager/OrderEmailManager.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,42 @@ | ||
<?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\AdminBundle\EmailManager; | ||
|
||
use Sylius\Bundle\CoreBundle\Mailer\Emails; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Mailer\Sender\SenderInterface; | ||
|
||
final class OrderEmailManager implements OrderEmailManagerInterface | ||
{ | ||
/** @var SenderInterface */ | ||
private $emailSender; | ||
|
||
public function __construct(SenderInterface $emailSender) | ||
{ | ||
$this->emailSender = $emailSender; | ||
} | ||
|
||
public function sendConfirmationEmail(OrderInterface $order): void | ||
{ | ||
$this->emailSender->send( | ||
Emails::ORDER_CONFIRMATION_RESENT, | ||
[$order->getCustomer()->getEmail()], | ||
[ | ||
'order' => $order, | ||
'channel' => $order->getChannel(), | ||
'localeCode' => $order->getLocaleCode(), | ||
] | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Sylius/Bundle/AdminBundle/EmailManager/OrderEmailManagerInterface.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,21 @@ | ||
<?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\AdminBundle\EmailManager; | ||
|
||
use Sylius\Component\Core\Model\OrderInterface; | ||
|
||
interface OrderEmailManagerInterface | ||
{ | ||
public function sendConfirmationEmail(OrderInterface $order): void; | ||
} |
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
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
29 changes: 29 additions & 0 deletions
29
src/Sylius/Bundle/AdminBundle/Resources/views/Email/orderConfirmation.html.twig
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,29 @@ | ||
{% extends '@SyliusAdmin/Email/layout.html.twig' %} | ||
|
||
{% block subject %} | ||
{{ 'sylius.email.order_confirmation.subject'|trans({}, null, localeCode) }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
{% set url = channel.hostname is not null ? 'http://' ~ channel.hostname ~ path('sylius_shop_order_show', {'tokenValue': order.tokenValue, '_locale': localeCode}) : url('sylius_shop_order_show', {'tokenValue': order.tokenValue, '_locale': localeCode}) %} | ||
|
||
<div style="text-align: center; margin-bottom: 30px;"> | ||
{{ 'sylius.email.order_confirmation.your_order_number'|trans({}, null, localeCode) }} | ||
<div style="margin: 10px 0;"> | ||
<span style="border: 1px solid #eee; padding: 10px; color: #1abb9c; font-size: 28px;"> | ||
{{ order.number }} | ||
</span> | ||
</div> | ||
{{ 'sylius.email.order_confirmation.has_been_successfully_placed'|trans({}, null, localeCode) }} | ||
</div> | ||
|
||
<div style="text-align: center; margin-bottom: 30px;"> | ||
<a href="{{ url|raw }}" style="display: inline-block; text-align: center; background: #1abb9c; padding: 18px 28px; color: #fff; text-decoration: none; border-radius: 3px;"> | ||
{{ 'sylius.email.order_confirmation.view_order_or_change_payment_method'|trans({}, null, localeCode) }} | ||
</a> | ||
</div> | ||
|
||
<div style="text-align: center;"> | ||
{{ 'sylius.email.order_confirmation.thank_you'|trans({}, null, localeCode) }} | ||
</div> | ||
{% endblock %} |
6 changes: 6 additions & 0 deletions
6
src/Sylius/Bundle/AdminBundle/Resources/views/Order/Show/_resendEmail.html.twig
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,6 @@ | ||
<div class="ui segment"> | ||
{% set path = path('sylius_admin_order_resend_confirmation_email', {'id': order.id, '_csrf_token': csrf_token(order.id)}) %} | ||
<a href="{{ path }}" class="ui icon labeled tiny fluid button" {{ sylius_test_html_attribute('resend-order-confirmation-email') }}> | ||
<i class="send icon"></i> {{ 'sylius.ui.resend_the_order_confirmation_email'|trans }} | ||
</a> | ||
</div> |
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
57 changes: 57 additions & 0 deletions
57
src/Sylius/Bundle/AdminBundle/spec/EmailManager/OrderEmailManagerSpec.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,57 @@ | ||
<?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 spec\Sylius\Bundle\AdminBundle\EmailManager; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Bundle\AdminBundle\EmailManager\OrderEmailManagerInterface; | ||
use Sylius\Component\Core\Model\ChannelInterface; | ||
use Sylius\Component\Core\Model\CustomerInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Mailer\Sender\SenderInterface; | ||
|
||
final class OrderEmailManagerSpec extends ObjectBehavior | ||
{ | ||
function let(SenderInterface $sender): void | ||
{ | ||
$this->beConstructedWith($sender); | ||
} | ||
|
||
function it_implements_an_order_email_manager_interface(): void | ||
{ | ||
$this->shouldImplement(OrderEmailManagerInterface::class); | ||
} | ||
|
||
function it_sends_an_order_confirmation_email( | ||
SenderInterface $sender, | ||
OrderInterface $order, | ||
ChannelInterface $channel, | ||
CustomerInterface $customer | ||
): void { | ||
$order->getChannel()->willReturn($channel); | ||
$order->getLocaleCode()->willReturn('en_US'); | ||
$order->getCustomer()->willReturn($customer); | ||
$customer->getEmail()->willReturn('[email protected]'); | ||
|
||
$sender | ||
->send('order_confirmation_resent', ['[email protected]'], [ | ||
'order' => $order, | ||
'channel' => $channel, | ||
'localeCode' => 'en_US', | ||
]) | ||
->shouldBeCalled() | ||
; | ||
|
||
$this->sendConfirmationEmail($order); | ||
} | ||
} |
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