diff --git a/src/Controller/Action/ResendGiftCardEmailAction.php b/src/Controller/Action/ResendGiftCardEmailAction.php new file mode 100644 index 00000000..020a62e5 --- /dev/null +++ b/src/Controller/Action/ResendGiftCardEmailAction.php @@ -0,0 +1,92 @@ +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'); + } +} diff --git a/src/Model/GiftCard.php b/src/Model/GiftCard.php index 60223669..f4ff2dcb 100644 --- a/src/Model/GiftCard.php +++ b/src/Model/GiftCard.php @@ -235,4 +235,9 @@ public function getChannelCode(): ?string return $channel->getCode(); } + + public function hasAssociatedOrderOrCustomer(): bool + { + return $this->getCustomer() instanceof CustomerInterface || $this->getOrder() instanceof OrderInterface; + } } diff --git a/src/Model/GiftCardInterface.php b/src/Model/GiftCardInterface.php index f60174d3..626561ab 100644 --- a/src/Model/GiftCardInterface.php +++ b/src/Model/GiftCardInterface.php @@ -104,4 +104,6 @@ public function getCustomerIdentification(): ?array; public function getOrderIdentification(): ?array; public function getChannelCode(): ?string; + + public function hasAssociatedOrderOrCustomer(): bool; } diff --git a/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml b/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml index cecf7852..06ac3322 100644 --- a/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml +++ b/src/Resources/config/grids/setono_sylius_gift_card_admin_gift_card.yaml @@ -5,6 +5,7 @@ sylius_grid: delete_conditional: "@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Action/delete_conditional.html.twig" gift_card_balance: "@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Action/gift_card_balance.html.twig" list_conditional: "@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Action/list_conditional.html.twig" + resend_gift_card_email: '@SetonoSyliusGiftCardPlugin/Admin/GiftCard/Grid/Action/resend_email.html.twig' grids: setono_sylius_gift_card_admin_gift_card: driver: @@ -113,6 +114,15 @@ sylius_grid: route: setono_sylius_gift_card_admin_gift_card_pdf parameters: id: resource.id + resend_email: + type: resend_gift_card_email + label: setono_sylius_gift_card.ui.resend_email + options: + visible: resource.hasAssociatedOrderOrCustomer + link: + route: setono_sylius_gift_card_admin_gift_card_resend_email + parameters: + id: resource.id delete: type: delete_conditional options: diff --git a/src/Resources/config/routes/admin.yaml b/src/Resources/config/routes/admin.yaml index c06391f6..aecdfa69 100644 --- a/src/Resources/config/routes/admin.yaml +++ b/src/Resources/config/routes/admin.yaml @@ -25,6 +25,16 @@ setono_sylius_gift_card_admin_gift_card_pdf: _sylius: section: admin +setono_sylius_gift_card_admin_gift_card_resend_email: + path: /gift-cards/{id}/resend-email + requirements: + id: \d+ + methods: [ GET ] + defaults: + _controller: setono_sylius_gift_card.controller.action.resend_email + _sylius: + section: admin + setono_sylius_gift_card_admin_gift_card_configuration: resource: | alias: setono_sylius_gift_card.gift_card_configuration diff --git a/src/Resources/config/services/controller.xml b/src/Resources/config/services/controller.xml index 5c0641d3..b261b637 100644 --- a/src/Resources/config/services/controller.xml +++ b/src/Resources/config/services/controller.xml @@ -48,6 +48,14 @@ + + + + + + + diff --git a/src/Resources/translations/flashes.en.yml b/src/Resources/translations/flashes.en.yml index e07d3288..158a20ec 100644 --- a/src/Resources/translations/flashes.en.yml +++ b/src/Resources/translations/flashes.en.yml @@ -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 diff --git a/src/Resources/translations/flashes.fr.yml b/src/Resources/translations/flashes.fr.yml index d3d234ff..8ed53fe6 100644 --- a/src/Resources/translations/flashes.fr.yml +++ b/src/Resources/translations/flashes.fr.yml @@ -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 diff --git a/src/Resources/translations/messages.en.yml b/src/Resources/translations/messages.en.yml index 7b5236c2..8bcd30dc 100644 --- a/src/Resources/translations/messages.en.yml +++ b/src/Resources/translations/messages.en.yml @@ -16,9 +16,11 @@ setono_sylius_gift_card: ui: active: Active add_gift_card_to_order: Add gift card - covered_by_gift_cards: Covered by gift cards amount: Amount + applied_gift_cards: Applied gift cards average_amount: Average amount + bought_at_order: Bought at order + covered_by_gift_cards: Covered by gift cards count: Count create_for_channel: Create for %channel% download_pdf: PDF @@ -31,10 +33,8 @@ setono_sylius_gift_card: gift_card_code_is_invalid: Gift card code is invalid gift_cards: Gift cards gift_card_search: Gift card search - applied_gift_cards: Applied gift cards gift_cards_adjustment_total: Gift cards total initial_amount: Initial amount - bought_at_order: Bought at order list_orders: List orders manage_gift_cards: Manage gift cards manage_gift_card_configurations: Manage gift card configurations @@ -42,6 +42,7 @@ setono_sylius_gift_card: new_gift_card_configuration: New gift card configuration manually_created: Manually created no_gift_card: No gift card applied + resend_email: Resend email total: Total your_gift_card_will_only_be_charged_if_you_complete_your_order: Your gift card will only be charged if you complete your order email: diff --git a/src/Resources/translations/messages.fr.yml b/src/Resources/translations/messages.fr.yml index 43ed05c4..308f7d69 100644 --- a/src/Resources/translations/messages.fr.yml +++ b/src/Resources/translations/messages.fr.yml @@ -16,9 +16,11 @@ setono_sylius_gift_card: ui: active: Actif add_gift_card_to_order: Ajouter le chèque-cadeau - covered_by_gift_cards: Montant pris en charge amount: Montant + applied_gift_cards: Chèques-cadeaux utilisés average_amount: Montant moyen + bought_at_order: Commande d'origine + covered_by_gift_cards: Montant pris en charge count: Nombre create_for_channel: Créer pour %channel% download_pdf: PDF @@ -31,10 +33,8 @@ setono_sylius_gift_card: gift_card_code_is_invalid: Numéro de chèque-cadeau invalide gift_cards: Chèques-cadeaux gift_card_search: Chercher un chèque cadeau - applied_gift_cards: Chèques-cadeaux utilisés gift_cards_adjustment_total: Montant des chèques-cadeaux initial_amount: Montant initial - bought_at_order: Commande d'origine list_orders: Lister les commandes manage_gift_cards: Gérer les chèques-cadeaux manage_gift_card_configurations: Gérer les configurations de chèques-cadeaux @@ -42,11 +42,14 @@ setono_sylius_gift_card: new_gift_card_configuration: Nouvelle configuration de chèque-cadeau manually_created: Créé manuellement no_gift_card: Pas de chèque-cadeau utilisé + resend_email: Renvoyer l'email total: Total your_gift_card_will_only_be_charged_if_you_complete_your_order: Votre chèque-cadeau ne sera débité que si vous complétez votre commande email: - your_gift_card: Votre chèque cadeau balance: Solde + new_gift_card: Nouveau chèque-cadeau + new_gift_card_intro: Un nouveau chèque-cadeau a été créé pour vous + your_gift_card: Votre chèque cadeau your_gift_cards_you_bought_in_the_order: Vos chèques-cadeaux achetés avec cette commande # Missing from Sylius for some reason diff --git a/src/Resources/views/Admin/GiftCard/Grid/Action/resend_email.html.twig b/src/Resources/views/Admin/GiftCard/Grid/Action/resend_email.html.twig new file mode 100644 index 00000000..1731f884 --- /dev/null +++ b/src/Resources/views/Admin/GiftCard/Grid/Action/resend_email.html.twig @@ -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 %}