Skip to content

Commit

Permalink
feature #10932 [Admin][Order] Add resending an order confirmation ema…
Browse files Browse the repository at this point in the history
…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
lchrusciel authored Dec 16, 2019
2 parents a8c244d + d7baba1 commit 8f56c30
Show file tree
Hide file tree
Showing 20 changed files with 336 additions and 6 deletions.
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
19 changes: 19 additions & 0 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ public function iFilter()
$this->indexPage->filter();
}

/**
* @When I resend the order confirmation email
*/
public function iResendTheOrderConfirmationEmail(): void
{
$this->showPage->resendOrderConfirmationEmail();
}

/**
* @Then I should see a single order from customer :customer
*/
Expand Down Expand Up @@ -881,6 +889,17 @@ public function iShouldSeeInformationAboutNoPayments(): void
Assert::true($this->showPage->hasInformationAboutNoPayment());
}

/**
* @Then I should be notified that the order confirmation email has been successfully resent to the customer
*/
public function iShouldBeNotifiedThatTheOrderConfirmationEmailHasBeenSuccessfullyResentToTheCustomer(): void
{
$this->notificationChecker->checkNotification(
'Order confirmation has been successfully resent to the customer.',
NotificationType::success()
);
}

/**
* @param string $type
* @param string $element
Expand Down
22 changes: 17 additions & 5 deletions src/Sylius/Behat/Context/Ui/EmailContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,34 @@ public function aWelcomingEmailShouldHaveBeenSentTo(string $recipient, string $l
}

/**
* @Then /^an email with the summary of (order placed by "[^"]+") should be sent to him$/
* @Then /^an email with the summary of (order placed by "[^"]+") should be sent to him in ("([^"]+)" locale)$/
* @Then an email with the confirmation of the order :order should be sent to :email
* @Then an email with the confirmation of the order :order should be sent to :email in :localeCode locale
*/
public function anEmailWithOrderConfirmationShouldBeSentTo(OrderInterface $order, string $localeCode = 'en_US'): void
{
public function anEmailWithTheConfirmationOfTheOrderShouldBeSentTo(
OrderInterface $order,
string $recipient,
string $localeCode = 'en_US'
): void {
$this->assertEmailContainsMessageTo(
sprintf(
'%s %s %s',
$this->translator->trans('sylius.email.order_confirmation.your_order_number', [], null, $localeCode),
$order->getNumber(),
$this->translator->trans('sylius.email.order_confirmation.has_been_successfully_placed', [], null, $localeCode)
),
$order->getCustomer()->getEmailCanonical()
$recipient
);
}

/**
* @Then /^an email with the summary of (order placed by "[^"]+") should be sent to him$/
* @Then /^an email with the summary of (order placed by "[^"]+") should be sent to him in ("([^"]+)" locale)$/
*/
public function anEmailWithSummaryOfOrderPlacedByShouldBeSentTo(OrderInterface $order, string $localeCode = 'en_US'): void
{
$this->anEmailWithTheConfirmationOfTheOrderShouldBeSentTo($order, $order->getCustomer()->getEmailCanonical(), $localeCode);
}

/**
* @Then /^an email with shipment's details of (this order) should be sent to "([^"]+)"$/
* @Then /^an email with shipment's details of (this order) should be sent to "([^"]+)" in ("([^"]+)" locale)$/
Expand Down
6 changes: 6 additions & 0 deletions src/Sylius/Behat/Page/Admin/Order/ShowPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ public function hasInformationAboutNoPayment(): bool
return $this->getDocument()->has('css', '#no-payments:contains("Order without payments")');
}

public function resendOrderConfirmationEmail(): void
{
$this->getElement('resend_order_confirmation_email')->click();
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
Expand All @@ -383,6 +388,7 @@ protected function getDefinedElements(): array
'promotion_discounts' => '#promotion-discounts',
'promotion_shipping_discounts' => '#shipping-discount-value',
'promotion_total' => '#promotion-total',
'resend_order_confirmation_email' => '[data-test-resend-order-confirmation-email]',
'shipments' => '#sylius-shipments',
'shipping_address' => '#shipping-address',
'shipping_adjustment_name' => '#shipping-adjustment-label',
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Page/Admin/Order/ShowPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ public function getShippingPromotionData(): string;
public function getItemOrderDiscount(string $itemName): string;

public function hasInformationAboutNoPayment(): bool;

public function resendOrderConfirmationEmail(): void;
}
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 src/Sylius/Bundle/AdminBundle/EmailManager/OrderEmailManager.php
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(),
]
);
}
}
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

sylius_mailer:
emails:
order_confirmation_resent:
subject: sylius.emails.order_confirmation.subject
template: "@SyliusAdmin/Email/orderConfirmation.html.twig"
shipment_confirmation:
subject: sylius.emails.shipment_confirmation.subject
template: "@SyliusAdmin/Email/shipmentConfirmation.html.twig"
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,9 @@ sylius_admin_order_shipment_ship:
parameters:
orderId: $orderId
id: $id

sylius_admin_order_resend_confirmation_email:
path: /{id}/resend-confirmation-email
methods: [GET]
defaults:
_controller: Sylius\Bundle\AdminBundle\Action\ResendOrderConfirmationEmailAction
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
<argument type="service" id="security.csrf.token_manager" />
</service>

<service id="Sylius\Bundle\AdminBundle\Action\ResendOrderConfirmationEmailAction" public="true">
<argument type='service' id="sylius.repository.order" />
<argument type="service" id="Sylius\Bundle\AdminBundle\EmailManager\OrderEmailManagerInterface" />
<argument type="service" id="security.csrf.token_manager" />
<argument type="service" id="session" />
</service>

<service id="sylius.controller.admin.dashboard" class="Sylius\Bundle\AdminBundle\Controller\DashboardController" public="true">
<argument type="service" id="sylius.dashboard.statistics_provider" />
<argument type="service" id="sylius.repository.channel" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<services>
<defaults public="true" />

<service id="Sylius\Bundle\AdminBundle\EmailManager\OrderEmailManagerInterface" class="Sylius\Bundle\AdminBundle\EmailManager\OrderEmailManager">
<argument type="service" id="sylius.email_sender" />
</service>

<service id="sylius.email_manager.shipment" class="Sylius\Bundle\AdminBundle\EmailManager\ShipmentEmailManager">
<argument type="service" id="sylius.email_sender" />
</service>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
# (c) Paweł Jędrzejewski

sylius:
email:
order_confirmation_resent: 'Order confirmation has been successfully resent to the customer.'
product_variant:
cannot_generate_variants: 'Cannot generate variants for a product without options values.'
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div style="max-width: 600px; margin: 20px auto;">
<div style="margin-bottom: 30px; text-align: center;">
<a href="{{ absolute_url(path('sylius_shop_homepage')) }}">
<img src="{{ absolute_url(asset('assets/shop/img/logo.png')) }}" alt="Sylius" style="width: 170px">
<img src="{{ absolute_url(asset('assets/admin/img/logo.png')) }}" alt="Sylius" style="width: 170px">
</a>
</div>

Expand Down
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 %}
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>
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

{% include '@SyliusAdmin/Order/Show/_payments.html.twig' %}
{% include '@SyliusAdmin/Order/Show/_shipments.html.twig' %}
{% include '@SyliusAdmin/Order/Show/_resendEmail.html.twig' %}

{{ sonata_block_render_event('sylius.admin.order.show.after_shipments', {'resource': resource}) }}
</div>
Expand Down
Loading

0 comments on commit 8f56c30

Please sign in to comment.