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

[5.3] Add env support for email email fields #3761

Merged
merged 3 commits into from
Nov 20, 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
3 changes: 2 additions & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

## Administration

- Added support for `to`, `bcc`, and `cc` email fields to support environment variables. ([#3738](https://github.com/craftcms/commerce/issues/3738))
- Added an `originalCart` value to the `commerce/update-cart` failed ajax response. ([#430](https://github.com/craftcms/commerce/issues/430))
- Added a new "Payment Gateway" order condition rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722))
- Added a new "Payment Gateway" order condition rule. ([#3722](https://github.com/craftcms/commerce/discussions/3722))
117 changes: 102 additions & 15 deletions src/models/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -53,21 +56,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
*/
Expand Down Expand Up @@ -114,6 +102,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
*/
Expand Down Expand Up @@ -233,6 +245,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
Expand Down
17 changes: 10 additions & 7 deletions src/templates/settings/emails/_edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@
</div>
<div id="to-option-custom"
class="flex-grow{% if email.recipientType != 'custom' %} hidden{% endif %}">
{{ forms.text({
{{ forms.autosuggestField({
id: 'to',
name: 'to',
value: email.to,
placeholder: '[email protected], [email protected]'
value: email.getTo(false),
errors: email.getErrors('to'),
suggestEnvVars: true,
}) }}
</div>
</div>
Expand All @@ -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({
Expand Down
Loading