Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/SWEHY-15 #6

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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 IS_ENABLED = 'hyva_themes_checkout/new_customer/enable';
private const SEND_RESET_PASSWORD_MAIL = 'hyva_themes_checkout/new_customer/send_reset_password_mail';
private const NEW_PASSWORD_TEMPLATE = 'hyva_themes_checkout/new_customer/create_password_template';

public function __construct(private ScopeConfigInterface $scopeConfig)
{
}

public function isEnabled(): bool
{
return (bool)$this->scopeConfig->getValue(
self::IS_ENABLED,
ScopeInterface::SCOPE_STORE
);
}

public function sendPasswordMailEnabled(): bool
{
return (bool)$this->scopeConfig->getValue(
self::SEND_RESET_PASSWORD_MAIL,
ScopeInterface::SCOPE_STORE
);
}

public function getNewPasswordTemplate(): string
{
return $this->scopeConfig->getValue(
self::NEW_PASSWORD_TEMPLATE,
ScopeInterface::SCOPE_STORE
);
}
}
10 changes: 7 additions & 3 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 @@ -56,7 +58,9 @@ public function execute(Observer $observer): void
// Ideally we should make this configurable.
->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);

$this->sendPasswordResetEmail($customer->getEmail());
if ($this->newAccountConfig->sendPasswordMailEnabled()) {
$this->sendPasswordResetEmail($customer->getEmail());
}
}

private function createNewCustomerFromQuote(Quote $quote): ?\Magento\Customer\Api\Data\CustomerInterface
Expand Down Expand Up @@ -84,7 +88,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_HyvaCheckoutCreateAccount::system/new_customer.xml"/>
</section>
</system>
</config>
54 changes: 54 additions & 0 deletions etc/adminhtml/system/new_customer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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="enable"
type="select"
translate="label"
showInDefault="1"
showInWebsite="1"
showInStore="1"
canRestore="1">
<label>Enable New Customer</label>
<comment>Will add a checkbox to checkout for creating a new account.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>

<field id="send_reset_password_mail"
type="select"
translate="label"
showInDefault="1"
showInWebsite="1"
showInStore="1"
canRestore="1">
<label>Send Reset Password Mail</label>
<comment>This will send a reset password mail after creating a new account.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="enable">1</field>
</depends>
</field>

<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>
<depends>
<field id="enable">1</field>
</depends>
</field>

</group>
</include>
12 changes: 12 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<hyva_themes_checkout>
<new_customer>
<enable>1</enable>
<send_reset_password_mail>1</send_reset_password_mail>
<create_password_template>hyva_themes_checkout_new_customer_create_password_template</create_password_template>
</new_customer>
</hyva_themes_checkout>
</default>
</config>
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>
4 changes: 3 additions & 1 deletion view/frontend/layout/hyva_checkout_components.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<body>
<referenceContainer name="checkout.section.quote-actions">
<container name="create-account.wrapper" htmlTag="div" htmlClass="mt-4">
<block name="create-account" template="Vendic_HyvaCheckoutCreateAccount::create-account.phtml">
<block name="create-account"
template="Vendic_HyvaCheckoutCreateAccount::create-account.phtml"
ifconfig="hyva_themes_checkout/new_customer/enable">
<block name="create-account.checkbox" as="checkbox">
<arguments>
<argument name="magewire" xsi:type="object">
Expand Down