c64girl Posted August 1, 2024 Share Posted August 1, 2024 I dont know why there is no information to client when You create a acount in back office? I found the file that is responsible for creation user in backoffice is in src/Adapter/Customer/CommandHandler/AddCustomerHandler.php I was trying to auto attach the recover password email template but no luck with that. Link to comment Share on other sites More sharing options...
c64girl Posted August 1, 2024 Author Share Posted August 1, 2024 (edited) Edit 2: Ok i found the way, in ps 1.7.8.11 edit: src/Adapter/Customer/CommandHandler/AddCustomerHandler.php Added to code On top: use Mail; In middle: // Send welcome email to customer $this->sendCustomerWelcomeEmail($customer, $command->getPassword()->getValue()); At end bfore last } /** * Sends a welcome email to the newly added customer * * @param Customer $customer */ private function sendCustomerWelcomeEmail(Customer $customer, $plainPassword) { $templateVars = [ '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, ]; $languageId = $customer->id_lang ? (int) $customer->id_lang : 1; $mailSent = Mail::Send( $languageId, 'account', Mail::l('Welcome!', $languageId), $templateVars, $customer->email, $customer->firstname . ' ' . $customer->lastname ); if (!$mailSent) { // Handle the case where the email could not be sent throw new \RuntimeException('Failed to send welcome email to customer'); } } Edited code look like this: namespace PrestaShop\PrestaShop\Adapter\Customer\CommandHandler; use Customer; use Mail; use PrestaShop\PrestaShop\Core\Crypto\Hashing; use PrestaShop\PrestaShop\Core\Domain\Customer\Command\AddCustomerCommand; use PrestaShop\PrestaShop\Core\Domain\Customer\CommandHandler\AddCustomerHandlerInterface; use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerDefaultGroupAccessException; use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerException; use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\DuplicateCustomerEmailException; use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId; use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\RequiredField; use PrestaShop\PrestaShop\Core\Domain\ValueObject\Email; /** * Handles command that adds new customer * * @internal */ final class AddCustomerHandler extends AbstractCustomerHandler implements AddCustomerHandlerInterface { /** * @var Hashing */ private $hashing; /** * @var string Value of legacy _COOKIE_KEY_ */ private $legacyCookieKey; /** * @param Hashing $hashing * @param string $legacyCookieKey */ public function __construct(Hashing $hashing, $legacyCookieKey) { $this->hashing = $hashing; $this->legacyCookieKey = $legacyCookieKey; } /** * {@inheritdoc} */ public function handle(AddCustomerCommand $command) { $customer = new Customer(); $this->fillCustomerWithCommandData($customer, $command); // validateFieldsRequiredDatabase() below is using $_POST // to check if required fields are set $_POST[RequiredField::PARTNER_OFFERS] = $command->isPartnerOffersSubscribed(); $this->assertRequiredFieldsAreNotMissing($customer); if (false === $customer->validateFields(false)) { throw new CustomerException('Customer contains invalid field values'); } $this->assertCustomerWithGivenEmailDoesNotExist($command->getEmail()); $this->assertCustomerCanAccessDefaultGroup($command); $customer->add(); // Send welcome email to customer $this->sendCustomerWelcomeEmail($customer, $command->getPassword()->getValue()); return new CustomerId((int) $customer->id); } /** * @param Email $email */ private function assertCustomerWithGivenEmailDoesNotExist(Email $email) { $customer = new Customer(); $customer->getByEmail($email->getValue()); if ($customer->id) { throw new DuplicateCustomerEmailException($email, sprintf('Customer with email "%s" already exists', $email->getValue())); } } /** * @param Customer $customer * @param AddCustomerCommand $command */ private function fillCustomerWithCommandData(Customer $customer, AddCustomerCommand $command) { $apeCode = null !== $command->getApeCode() ? $command->getApeCode()->getValue() : null; $hashedPassword = $this->hashing->hash( $command->getPassword()->getValue(), $this->legacyCookieKey ); $customer->firstname = $command->getFirstName()->getValue(); $customer->lastname = $command->getLastName()->getValue(); $customer->email = $command->getEmail()->getValue(); $customer->passwd = $hashedPassword; $customer->id_default_group = $command->getDefaultGroupId(); $customer->groupBox = $command->getGroupIds(); $customer->id_gender = $command->getGenderId(); $customer->active = $command->isEnabled(); $customer->optin = $command->isPartnerOffersSubscribed(); $customer->birthday = $command->getBirthday()->getValue(); $customer->id_shop = $command->getShopId(); // fill b2b customer fields $customer->company = $command->getCompanyName(); $customer->siret = $command->getSiretCode(); $customer->ape = $apeCode; $customer->website = $command->getWebsite(); $customer->outstanding_allow_amount = $command->getAllowedOutstandingAmount(); $customer->max_payment_days = $command->getMaxPaymentDays(); $customer->id_risk = $command->getRiskId(); } /** * @param AddCustomerCommand $command */ private function assertCustomerCanAccessDefaultGroup(AddCustomerCommand $command) { if (!in_array($command->getDefaultGroupId(), $command->getGroupIds())) { throw new CustomerDefaultGroupAccessException(sprintf('Customer default group with id "%s" must be in access groups', $command->getDefaultGroupId())); } } /** * Sends a welcome email to the newly added customer * * @param Customer $customer */ private function sendCustomerWelcomeEmail(Customer $customer, $plainPassword) { $templateVars = [ '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, ]; $languageId = $customer->id_lang ? (int) $customer->id_lang : 1; $mailSent = Mail::Send( $languageId, 'account', Mail::l('Welcome!', $languageId), $templateVars, $customer->email, $customer->firstname . ' ' . $customer->lastname ); if (!$mailSent) { // Handle the case where the email could not be sent throw new \RuntimeException('Failed to send welcome email to customer'); } } } Edited August 2, 2024 by c64girl Fixed code (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now