From 2ef66f8578dbcf8e449d148bfb6ec0e7d3028b91 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 13 Nov 2024 15:43:55 +0800 Subject: [PATCH 1/2] Add env support for email email fields --- CHANGELOG-WIP.md | 3 +- src/models/Email.php | 114 ++++++++++++++++++++--- src/templates/settings/emails/_edit.twig | 17 ++-- 3 files changed, 111 insertions(+), 23 deletions(-) diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index de991b6ce5..9610abe1ab 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -2,4 +2,5 @@ ## Administration -- Added a new "Payment Gateway" order condition rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722)) \ No newline at end of file +- Added a new "Payment Gateway" order condition rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722)) +- Added support for `to`, `bcc`, and `cc` email fields to support environment variables. ([#3738](https://github.com/craftcms/commerce/issues/3738)) \ No newline at end of file diff --git a/src/models/Email.php b/src/models/Email.php index 210b23ea18..f08bf4aff4 100644 --- a/src/models/Email.php +++ b/src/models/Email.php @@ -53,21 +53,6 @@ class Email extends Model implements HasStoreInterface */ public string $recipientType = EmailRecord::TYPE_CUSTOMER; - /** - * @var string|null To - */ - public ?string $to = null; - - /** - * @var string|null Bcc - */ - public ?string $bcc = null; - - /** - * @var string|null Cc - */ - public ?string $cc = null; - /** * @var string|null Reply to */ @@ -114,6 +99,30 @@ class Email extends Model implements HasStoreInterface */ private ?string $_senderName = null; + /** + * @var string|null + * @since 5.3.0 + * @see setBcc() + * @see getBcc() + */ + private ?string $_bcc = null; + + /** + * @var string|null + * @since 5.3.0 + * @see setBcc() + * @see getBcc() + */ + private ?string $_cc = null; + + /** + * @var string|null + * @since 5.3.0 + * @see setTo() + * @see getTo() + */ + private ?string $_to = null; + /** * @var string|null UID */ @@ -233,6 +242,81 @@ public function getSenderAddress(bool $parse = true): ?string return $senderAddress; } + /** + * @param string|null $bcc + * @return void + * @since 5.3.0 + */ + public function setBcc(?string $bcc): void + { + $this->_bcc = $bcc; + } + + /** + * @param bool $parse + * @return string|null Default bcc email address Commerce emails should be sent to. + * + * @since 5.3.0 + */ + public function getBcc(bool $parse = true): ?string + { + if (!$parse) { + return $this->_bcc; + } + + return App::parseEnv($this->_bcc); + } + + /** + * @param string|null $cc + * @return void + * @since 5.3.0 + */ + public function setCc(?string $cc): void + { + $this->_cc = $cc; + } + + /** + * @param bool $parse + * @return string|null Default cc email address Commerce emails should be sent to. + * + * @since 5.3.0 + */ + public function getCc(bool $parse = true): ?string + { + if (!$parse) { + return $this->_cc; + } + + return App::parseEnv($this->_cc); + } + + /** + * @param string|null $to + * @return void + * @since 5.3.0 + */ + public function setTo(?string $to): void + { + $this->_to = $to; + } + + /** + * @param bool $parse + * @return string|null Default to email address Commerce emails should be sent to. + * + * @since 5.3.0 + */ + public function getTo(bool $parse = true): ?string + { + if (!$parse) { + return $this->_to; + } + + return App::parseEnv($this->_to); + } + /** * @param string|null $senderName * @return void diff --git a/src/templates/settings/emails/_edit.twig b/src/templates/settings/emails/_edit.twig index 32207c8cba..90ec781600 100644 --- a/src/templates/settings/emails/_edit.twig +++ b/src/templates/settings/emails/_edit.twig @@ -89,11 +89,12 @@
- {{ forms.text({ + {{ forms.autosuggestField({ id: 'to', name: 'to', - value: email.to, - placeholder: 'jane@acme.com, joe@acme.com' + value: email.getTo(false), + errors: email.getErrors('to'), + suggestEnvVars: true, }) }}
@@ -107,22 +108,24 @@ required: true, }, recipientInput) }} - {{ forms.textField({ + {{ forms.autosuggestField({ label: 'BCC’d Recipient'|t('commerce'), instructions: 'Additional recipients that should receive this email. Twig code can be used here.'|t('commerce'), id: 'bcc', name: 'bcc', - value: email.bcc, + value: email.getBcc(false), errors: email.getErrors('bcc'), + suggestEnvVars: true, }) }} - {{ forms.textField({ + {{ forms.autosuggestField({ label: 'CC’d Recipient'|t('commerce'), instructions: 'Additional recipients that should receive this email. Twig code can be used here.'|t('commerce'), id: 'cc', name: 'cc', - value: email.cc, + value: email.getCc(false), errors: email.getErrors('cc'), + suggestEnvVars: true, }) }} {{ forms.autoSuggestField({ From c881d80edbfb0de14cdc0417d2fcc789768835b9 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 20 Nov 2024 21:57:10 +0800 Subject: [PATCH 2/2] FIx php docs --- src/models/Email.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/models/Email.php b/src/models/Email.php index f08bf4aff4..4a972c6a69 100644 --- a/src/models/Email.php +++ b/src/models/Email.php @@ -27,6 +27,9 @@ * @property-read string $pdfTemplatePath * @property-read null|Pdf $pdf * @property-read array $config + * @property ?string $bcc + * @property ?string $cc + * @property ?string $to * @property string|null $senderAddress */ class Email extends Model implements HasStoreInterface