diff --git a/Model/Config.php b/Model/Config.php new file mode 100644 index 0000000..e644bd1 --- /dev/null +++ b/Model/Config.php @@ -0,0 +1,44 @@ +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 + ); + } +} diff --git a/Observer/ConvertGuestToCustomer.php b/Observer/ConvertGuestToCustomer.php index e089b5c..a84cd7a 100644 --- a/Observer/ConvertGuestToCustomer.php +++ b/Observer/ConvertGuestToCustomer.php @@ -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 { @@ -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 ) { } @@ -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 @@ -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) { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml new file mode 100644 index 0000000..67030a2 --- /dev/null +++ b/etc/adminhtml/system.xml @@ -0,0 +1,9 @@ + + + +
+ +
+
+
diff --git a/etc/adminhtml/system/new_customer.xml b/etc/adminhtml/system/new_customer.xml new file mode 100644 index 0000000..ca73005 --- /dev/null +++ b/etc/adminhtml/system/new_customer.xml @@ -0,0 +1,54 @@ + + + + + + + + Will add a checkbox to checkout for creating a new account. + Magento\Config\Model\Config\Source\Yesno + + + + + This will send a reset password mail after creating a new account. + Magento\Config\Model\Config\Source\Yesno + + 1 + + + + + + Magento\Config\Model\Config\Source\Email\Template + + 1 + + + + + diff --git a/etc/config.xml b/etc/config.xml new file mode 100644 index 0000000..5540a8a --- /dev/null +++ b/etc/config.xml @@ -0,0 +1,12 @@ + + + + + + 1 + 1 + hyva_themes_checkout_new_customer_create_password_template + + + + diff --git a/etc/email_templates.xml b/etc/email_templates.xml new file mode 100644 index 0000000..314ba15 --- /dev/null +++ b/etc/email_templates.xml @@ -0,0 +1,4 @@ + + +