Skip to content

Commit

Permalink
Configurable email template for new password
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaahed committed Sep 29, 2023
1 parent 88f9623 commit 2f6f175
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php declare(strict_types=1);
/**
* @copyright Copyright (c) Vendic B.V https://vendic.nl/
*/

namespace Vendic\HyvaCheckoutCreateAccount\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Config
{
private const NEW_PASSWORD_TEMPLATE = 'hyva_themes_checkout/new_customer/create_password_template';

public function __construct(private ScopeConfigInterface $scopeConfig)
{
}

public function getNewPasswordTemplate(): string
{
return $this->scopeConfig->getValue(
self::NEW_PASSWORD_TEMPLATE,
ScopeInterface::SCOPE_STORE
);
}
}
6 changes: 4 additions & 2 deletions Observer/ConvertGuestToCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Magento\Checkout\Model\Session as CheckoutSession;
use Psr\Log\LoggerInterface;
use Vendic\HyvaCheckoutCreateAccount\Magewire\Checkbox;
use Vendic\HyvaCheckoutCreateAccount\Model\Config;

class ConvertGuestToCustomer implements ObserverInterface
{
Expand All @@ -26,7 +27,8 @@ public function __construct(
private AccountManagementInterface $accountManagement,
private StoreManagerInterface $storeManager,
private CheckoutSession $checkoutSession,
private LoggerInterface $logger
private LoggerInterface $logger,
private Config $newAccountConfig
) {
}

Expand Down Expand Up @@ -84,7 +86,7 @@ private function sendPasswordResetEmail(string $email): void
try {
$this->accountManagement->initiatePasswordReset(
$email,
AccountManagement::EMAIL_RESET,
$this->newAccountConfig->getNewPasswordTemplate(),
$this->storeManager->getStore()->getWebsiteId()
);
} catch (Exception $e) {
Expand Down
9 changes: 9 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="hyva_themes_checkout">
<include path="Vendic_HyvaCheckout::system/new_customer.xml"/>
</section>
</system>
</config>
24 changes: 24 additions & 0 deletions etc/adminhtml/system/new_customer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" ?>
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
<group id="new_customer"
showInDefault="1"
showInWebsite="1"
showInStore="1"
sortOrder="55"
translate="label">
<label>New Customer</label>

<field id="create_password_template"
type="select"
translate="label"
showInDefault="1"
showInWebsite="1"
showInStore="1"
canRestore="1">
<label>Create Password Template</label>
<source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
</field>

</group>
</include>
4 changes: 4 additions & 0 deletions etc/email_templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template id="hyva_themes_checkout_new_customer_create_password_template" label="Create Password" file="password_reset.html" type="html" module="Magento_Customer" area="frontend"/>
</config>

0 comments on commit 2f6f175

Please sign in to comment.