forked from Setono/SyliusFeedPlugin
-
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.
Allow to resend the GiftCard email via admin.yaml
Fixes Setono#17
- Loading branch information
Showing
11 changed files
with
154 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusGiftCardPlugin\Controller\Action; | ||
|
||
use const FILTER_SANITIZE_URL; | ||
use function filter_var; | ||
use Setono\SyliusGiftCardPlugin\EmailManager\GiftCardEmailManagerInterface; | ||
use Setono\SyliusGiftCardPlugin\Model\GiftCardInterface; | ||
use Setono\SyliusGiftCardPlugin\Model\OrderInterface; | ||
use Setono\SyliusGiftCardPlugin\Repository\GiftCardRepositoryInterface; | ||
use Sylius\Component\Core\Model\CustomerInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
final class ResendGiftCardEmailAction | ||
{ | ||
/** @var GiftCardEmailManagerInterface */ | ||
private $giftCardEmailManager; | ||
|
||
/** @var GiftCardRepositoryInterface */ | ||
private $giftCardRepository; | ||
|
||
/** @var FlashBagInterface */ | ||
private $flashBag; | ||
|
||
/** @var UrlGeneratorInterface */ | ||
private $router; | ||
|
||
public function __construct( | ||
GiftCardEmailManagerInterface $giftCardEmailManager, | ||
GiftCardRepositoryInterface $giftCardRepository, | ||
FlashBagInterface $flashBag, | ||
UrlGeneratorInterface $router | ||
) { | ||
$this->giftCardEmailManager = $giftCardEmailManager; | ||
$this->giftCardRepository = $giftCardRepository; | ||
$this->flashBag = $flashBag; | ||
$this->router = $router; | ||
} | ||
|
||
public function __invoke(Request $request, int $id): Response | ||
{ | ||
$giftCard = $this->giftCardRepository->find($id); | ||
if (!$giftCard instanceof GiftCardInterface) { | ||
$this->flashBag->add('error', [ | ||
'message' => 'setono_sylius_gift_card.gift_card.not_found', | ||
'parameters' => ['%id%' => $id], | ||
]); | ||
|
||
return new RedirectResponse($this->getRedirectRoute($request)); | ||
} | ||
|
||
if ($giftCard->getOrder() instanceof OrderInterface) { | ||
$this->giftCardEmailManager->sendEmailWithGiftCardsFromOrder($giftCard->getOrder(), [$giftCard]); | ||
$this->flashBag->add('success', [ | ||
'message' => 'setono_sylius_gift_card.gift_card.resent', | ||
'parameters' => ['%id%' => $id], | ||
]); | ||
} elseif ($giftCard->getCustomer() instanceof CustomerInterface) { | ||
$this->giftCardEmailManager->sendEmailToCustomerWithGiftCard($giftCard->getCustomer(), $giftCard); | ||
$this->flashBag->add('success', [ | ||
'message' => 'setono_sylius_gift_card.gift_card.resent', | ||
'parameters' => ['%id%' => $id], | ||
]); | ||
} else { | ||
$this->flashBag->add('error', [ | ||
'message' => 'setono_sylius_gift_card.gift_card.impossible_to_resend_email', | ||
'parameters' => ['%id%' => $id], | ||
]); | ||
} | ||
|
||
return new RedirectResponse($this->getRedirectRoute($request)); | ||
} | ||
|
||
private function getRedirectRoute(Request $request): string | ||
{ | ||
if ($request->headers->has('referer')) { | ||
$filtered = filter_var($request->headers->get('referer'), FILTER_SANITIZE_URL); | ||
|
||
if (false === $filtered) { | ||
return $this->router->generate('gift_card_admin_gift_card_index'); | ||
} | ||
} | ||
|
||
return $this->router->generate('gift_card_admin_gift_card_index'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
setono_sylius_gift_card: | ||
gift_card: | ||
delete_error: The gift card code can't be removed. | ||
impossible_to_resend_email: 'Impossible to re send email for gift card with id "%id%"' | ||
not_found: 'Impossible to find gift card with id "%id%"' | ||
read_error: Impossible to view this gift card. | ||
resent: The email has successfully been resent | ||
gift_card_added: Gift card was added to your order | ||
gift_card_removed: Gift card removed from your 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
setono_sylius_gift_card: | ||
gift_card: | ||
delete_error: Le chèque-cadeau n'a pas pu être supprimé. | ||
impossible_to_resend_email: 'Impossible d''envoyer l''email pour le chèque-cadeau "%id%"' | ||
not_found: 'Impossible de trouver le chèque-cadeau "%id%"' | ||
read_error: Impossible the visualiser le chèque-cadeau. | ||
resent: L'email a bien été renvoyé | ||
gift_card_added: Le chèque-cadeau a été ajouté à votre commande | ||
gift_card_removed: Le chèque-cadeau a été supprimé de votre commande |
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
10 changes: 10 additions & 0 deletions
10
src/Resources/views/Admin/GiftCard/Grid/Action/resend_email.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,10 @@ | ||
{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %} | ||
|
||
|
||
{% set visible = options.visible is defined ? options.visible : true %} | ||
|
||
{% if visible %} | ||
{% set path = options.link.url|default(path(options.link.route, options.link.parameters)) %} | ||
|
||
{{ buttons.default(path, action.label, null, 'mail', 'purple') }} | ||
{% endif %} |