Skip to content

Commit

Permalink
Add new variables (#49)
Browse files Browse the repository at this point in the history
* Add new variables

* Repair tests

Co-authored-by: Hubert Krzysztofiak <[email protected]>
  • Loading branch information
HerbertIV and Hubert Krzysztofiak authored Jun 2, 2022
1 parent fb74b14 commit 835573e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/Cart/OrderCreatedVariables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace EscolaLms\TemplatesEmail\Cart;

use EscolaLms\Cart\Models\Order;
use EscolaLms\Core\Models\User;
use EscolaLms\Templates\Events\EventWrapper;

class OrderCreatedVariables extends CartVariables
{
const VAR_USER_NAME = '@VarUserName';

public static function mockedVariables(?User $user = null): array
{
$faker = \Faker\Factory::create();
return array_merge(parent::mockedVariables(), [
self::VAR_USER_NAME => $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(__('<h1>Hello :user_name!</h1><p>Thanks for your order.</p>', [
'user_name' => self::VAR_USER_NAME
])),
];
}
}
3 changes: 3 additions & 0 deletions src/Providers/CartTemplatesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

0 comments on commit 835573e

Please sign in to comment.