From 835573edfc4a034bc2ee6a4f7457320b047e0e53 Mon Sep 17 00:00:00 2001 From: Hubert Krzysztofiak <62691459+HerbertIV@users.noreply.github.com> Date: Thu, 2 Jun 2022 14:48:46 +0200 Subject: [PATCH] Add new variables (#49) * Add new variables * Repair tests Co-authored-by: Hubert Krzysztofiak --- src/Cart/OrderCreatedVariables.php | 54 +++++++++++++++++++ .../CartTemplatesServiceProvider.php | 3 ++ 2 files changed, 57 insertions(+) create mode 100644 src/Cart/OrderCreatedVariables.php diff --git a/src/Cart/OrderCreatedVariables.php b/src/Cart/OrderCreatedVariables.php new file mode 100644 index 0000000..0304cd2 --- /dev/null +++ b/src/Cart/OrderCreatedVariables.php @@ -0,0 +1,54 @@ + $faker->name(), + ]); + } + + public static function variablesFromEvent(EventWrapper $event): array + { + return array_merge(parent::variablesFromEvent($event), [ + self::VAR_USER_NAME => $event->getUser()->name + ]); + } + + public static function assignableClass(): ?string + { + return Order::class; + } + + public static function requiredVariables(): array + { + return [ + self::VAR_USER_NAME, + ]; + } + + public static function requiredVariablesInSection(string $sectionKey): array + { + return []; + } + + public static function defaultSectionsContent(): array + { + return [ + 'title' => __('Thank you for your order'), + 'content' => self::wrapWithMjml(__('

Hello :user_name!

Thanks for your order.

', [ + 'user_name' => self::VAR_USER_NAME + ])), + ]; + } +} diff --git a/src/Providers/CartTemplatesServiceProvider.php b/src/Providers/CartTemplatesServiceProvider.php index 5c1dd08..21c67bb 100644 --- a/src/Providers/CartTemplatesServiceProvider.php +++ b/src/Providers/CartTemplatesServiceProvider.php @@ -2,8 +2,10 @@ namespace EscolaLms\TemplatesEmail\Providers; +use EscolaLms\Cart\Events\OrderCreated; use EscolaLms\Cart\Events\ProductAttached; use EscolaLms\Templates\Facades\Template; +use EscolaLms\TemplatesEmail\Cart\OrderCreatedVariables; use EscolaLms\TemplatesEmail\Cart\ProductAttachedVariables; use EscolaLms\TemplatesEmail\Core\EmailChannel; use Illuminate\Support\ServiceProvider; @@ -13,5 +15,6 @@ class CartTemplatesServiceProvider extends ServiceProvider public function boot() { Template::register(ProductAttached::class, EmailChannel::class, ProductAttachedVariables::class); + Template::register(OrderCreated::class, EmailChannel::class, OrderCreatedVariables::class); } }