Skip to content

Commit 48d5213

Browse files
authored
Merge pull request #6 from Vendic/feature/SWEHY-15
Feature/SWEHY-15
2 parents 39abe6f + e152bce commit 48d5213

File tree

7 files changed

+133
-4
lines changed

7 files changed

+133
-4
lines changed

Model/Config.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
/**
3+
* @copyright Copyright (c) Vendic B.V https://vendic.nl/
4+
*/
5+
6+
namespace Vendic\HyvaCheckoutCreateAccount\Model;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Store\Model\ScopeInterface;
10+
11+
class Config
12+
{
13+
private const IS_ENABLED = 'hyva_themes_checkout/new_customer/enable';
14+
private const SEND_RESET_PASSWORD_MAIL = 'hyva_themes_checkout/new_customer/send_reset_password_mail';
15+
private const NEW_PASSWORD_TEMPLATE = 'hyva_themes_checkout/new_customer/create_password_template';
16+
17+
public function __construct(private ScopeConfigInterface $scopeConfig)
18+
{
19+
}
20+
21+
public function isEnabled(): bool
22+
{
23+
return (bool)$this->scopeConfig->getValue(
24+
self::IS_ENABLED,
25+
ScopeInterface::SCOPE_STORE
26+
);
27+
}
28+
29+
public function sendPasswordMailEnabled(): bool
30+
{
31+
return (bool)$this->scopeConfig->getValue(
32+
self::SEND_RESET_PASSWORD_MAIL,
33+
ScopeInterface::SCOPE_STORE
34+
);
35+
}
36+
37+
public function getNewPasswordTemplate(): string
38+
{
39+
return $this->scopeConfig->getValue(
40+
self::NEW_PASSWORD_TEMPLATE,
41+
ScopeInterface::SCOPE_STORE
42+
);
43+
}
44+
}

Observer/ConvertGuestToCustomer.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Checkout\Model\Session as CheckoutSession;
1818
use Psr\Log\LoggerInterface;
1919
use Vendic\HyvaCheckoutCreateAccount\Magewire\Checkbox;
20+
use Vendic\HyvaCheckoutCreateAccount\Model\Config;
2021

2122
class ConvertGuestToCustomer implements ObserverInterface
2223
{
@@ -26,7 +27,8 @@ public function __construct(
2627
private AccountManagementInterface $accountManagement,
2728
private StoreManagerInterface $storeManager,
2829
private CheckoutSession $checkoutSession,
29-
private LoggerInterface $logger
30+
private LoggerInterface $logger,
31+
private Config $newAccountConfig
3032
) {
3133
}
3234

@@ -56,7 +58,9 @@ public function execute(Observer $observer): void
5658
// Ideally we should make this configurable.
5759
->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
5860

59-
$this->sendPasswordResetEmail($customer->getEmail());
61+
if ($this->newAccountConfig->sendPasswordMailEnabled()) {
62+
$this->sendPasswordResetEmail($customer->getEmail());
63+
}
6064
}
6165

6266
private function createNewCustomerFromQuote(Quote $quote): ?\Magento\Customer\Api\Data\CustomerInterface
@@ -84,7 +88,7 @@ private function sendPasswordResetEmail(string $email): void
8488
try {
8589
$this->accountManagement->initiatePasswordReset(
8690
$email,
87-
AccountManagement::EMAIL_RESET,
91+
$this->newAccountConfig->getNewPasswordTemplate(),
8892
$this->storeManager->getStore()->getWebsiteId()
8993
);
9094
} catch (Exception $e) {

etc/adminhtml/system.xml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
4+
<system>
5+
<section id="hyva_themes_checkout">
6+
<include path="Vendic_HyvaCheckoutCreateAccount::system/new_customer.xml"/>
7+
</section>
8+
</system>
9+
</config>

etc/adminhtml/system/new_customer.xml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" ?>
2+
<include xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_include.xsd">
4+
<group id="new_customer"
5+
showInDefault="1"
6+
showInWebsite="1"
7+
showInStore="1"
8+
sortOrder="55"
9+
translate="label">
10+
<label>New Customer</label>
11+
12+
<field id="enable"
13+
type="select"
14+
translate="label"
15+
showInDefault="1"
16+
showInWebsite="1"
17+
showInStore="1"
18+
canRestore="1">
19+
<label>Enable New Customer</label>
20+
<comment>Will add a checkbox to checkout for creating a new account.</comment>
21+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
22+
</field>
23+
24+
<field id="send_reset_password_mail"
25+
type="select"
26+
translate="label"
27+
showInDefault="1"
28+
showInWebsite="1"
29+
showInStore="1"
30+
canRestore="1">
31+
<label>Send Reset Password Mail</label>
32+
<comment>This will send a reset password mail after creating a new account.</comment>
33+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
34+
<depends>
35+
<field id="enable">1</field>
36+
</depends>
37+
</field>
38+
39+
<field id="create_password_template"
40+
type="select"
41+
translate="label"
42+
showInDefault="1"
43+
showInWebsite="1"
44+
showInStore="1"
45+
canRestore="1">
46+
<label>Create Password Template</label>
47+
<source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
48+
<depends>
49+
<field id="enable">1</field>
50+
</depends>
51+
</field>
52+
53+
</group>
54+
</include>

etc/config.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
3+
<default>
4+
<hyva_themes_checkout>
5+
<new_customer>
6+
<enable>1</enable>
7+
<send_reset_password_mail>1</send_reset_password_mail>
8+
<create_password_template>hyva_themes_checkout_new_customer_create_password_template</create_password_template>
9+
</new_customer>
10+
</hyva_themes_checkout>
11+
</default>
12+
</config>

etc/email_templates.xml

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

view/frontend/layout/hyva_checkout_components.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<body>
55
<referenceContainer name="checkout.section.quote-actions">
66
<container name="create-account.wrapper" htmlTag="div" htmlClass="mt-4">
7-
<block name="create-account" template="Vendic_HyvaCheckoutCreateAccount::create-account.phtml">
7+
<block name="create-account"
8+
template="Vendic_HyvaCheckoutCreateAccount::create-account.phtml"
9+
ifconfig="hyva_themes_checkout/new_customer/enable">
810
<block name="create-account.checkbox" as="checkbox">
911
<arguments>
1012
<argument name="magewire" xsi:type="object">

0 commit comments

Comments
 (0)