Skip to content

Commit

Permalink
Set "Default Customer Group" from admin config for new customer
Browse files Browse the repository at this point in the history
  • Loading branch information
kis28viktor committed Mar 27, 2024
1 parent 6760ce2 commit 5642406
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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
);
}
}
2 changes: 1 addition & 1 deletion Observer/ConvertGuestToCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ 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();
Expand Down

0 comments on commit 5642406

Please sign in to comment.