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

Fix assigning new created customer to the order #12

Merged
merged 2 commits into from
Mar 27, 2024
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
10 changes: 10 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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';
private const DEFAULT_CUSTOMER_GROUP_XML_PATH = 'customer/create_account/default_group';

public function __construct(private ScopeConfigInterface $scopeConfig)
{
Expand Down Expand Up @@ -41,4 +42,13 @@ public function getNewPasswordTemplate(): string
ScopeInterface::SCOPE_STORE
);
}

public function getDefaultCustomerGroup(?int $storeId = null): int
{
return (int)$this->scopeConfig->getValue(
self::DEFAULT_CUSTOMER_GROUP_XML_PATH,
ScopeInterface::SCOPE_STORE,
$storeId
);
}
}
6 changes: 5 additions & 1 deletion Observer/ConvertGuestToCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public function execute(Observer $observer): void
$quote->setCustomerId($customer->getId())
->setCustomerIsGuest(0)
// Ideally we should make this configurable.
->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
->setCustomerGroupId($this->newAccountConfig->getDefaultCustomerGroup((int)$quote->getStoreId()));

/** @var \Magento\Sales\Model\Order $order */
$order = $observer->getEvent()->getOrder();
$order->setCustomerId($customer->getId());

if ($this->newAccountConfig->sendPasswordMailEnabled()) {
$this->sendPasswordResetEmail($customer->getEmail());
Expand Down
Loading