-
-
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.
feature #10932 [Admin][Order] Add resending an order confirmation ema…
…il (GSadee) This PR was merged into the 1.5-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Related tickets | fixes #10907 | License | MIT Based on #10936 ![screencapture-127-0-0-1-8007-admin-orders-23-2019-12-12-14_40_39](https://user-images.githubusercontent.com/6140884/70717269-47c35800-1cee-11ea-9d74-3ee6598ecf45.png) Commits ------- ccda8cd [Behat][Admin][Order] Add scenarios for resending an order confirmation email d7baba1 [Admin][Order] Add resending an order confirmation email
- Loading branch information
Showing
20 changed files
with
336 additions
and
6 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
features/order/managing_orders/resending_order_confirmation_email.feature
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,32 @@ | ||
@managing_orders | ||
Feature: Resending an order confirmation email for a chosen order | ||
In order to be able to send a lost email again | ||
As an Administrator | ||
I want to have the order confirmation email for a chosen order sent to the customer | ||
|
||
Background: | ||
Given the store operates on a single channel in "United States" | ||
And that channel allows to shop using "English (United States)" and "Polish (Poland)" locales | ||
And the store has a product "Angel T-Shirt" | ||
And the store ships everywhere for free | ||
And the store allows paying with "Cash on Delivery" | ||
And there is a customer "[email protected]" that placed an order "#00000666" | ||
And the customer bought a single "Angel T-Shirt" | ||
And the customer "Lucifer Morningstar" addressed it to "Seaside Fwy", "90802" "Los Angeles" in the "United States" with identical billing address | ||
And the customer chose "Free" shipping method with "Cash on Delivery" payment | ||
And I am logged in as an administrator | ||
|
||
@ui @email | ||
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 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 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
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
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
Oops, something went wrong.