Skip to content

Commit

Permalink
[TASK] Add Buyer Email Reply To Address
Browse files Browse the repository at this point in the history
Resolves: #318
  • Loading branch information
extcode committed Feb 9, 2021
1 parent 017d989 commit e3396aa
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 18 deletions.
65 changes: 50 additions & 15 deletions Classes/Service/MailHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class MailHandler implements SingletonInterface
*/
protected $buyerEmailBcc = '';

/**
* @var string
*/
protected $buyerEmailReplyTo = '';

/**
* @var string
*/
Expand Down Expand Up @@ -86,7 +91,7 @@ public function __construct()
/**
* Sets Plugin Settings
*/
public function setPluginSettings()
public function setPluginSettings(): void
{
$this->pluginSettings =
$this->configurationManager->getConfiguration(
Expand Down Expand Up @@ -117,6 +122,17 @@ public function setPluginSettings()
$this->setBuyerEmailBcc($this->pluginSettings['mail']['buyer']['bccAddress']);
}

if (!empty($this->pluginSettings['settings']['buyer'])
&& !empty($this->pluginSettings['settings']['buyer']['emailReplyToAddress'])
) {
$this->setBuyerEmailReplyTo($this->pluginSettings['settings']['buyer']['emailReplyToAddress']);
} elseif (!empty($this->pluginSettings['mail'])
&& !empty($this->pluginSettings['mail']['buyer'])
&& !empty($this->pluginSettings['mail']['buyer']['replyToAddress'])
) {
$this->setBuyerEmailReplyTo($this->pluginSettings['mail']['buyer']['replyToAddress']);
}

if (!empty($this->pluginSettings['settings']['seller'])
&& !empty($this->pluginSettings['settings']['seller']['emailFromAddress'])
) {
Expand Down Expand Up @@ -155,7 +171,7 @@ public function setPluginSettings()
/**
* @param Cart $cart
*/
public function setCart(Cart $cart)
public function setCart(Cart $cart): void
{
$this->cart = $cart;
}
Expand Down Expand Up @@ -192,6 +208,22 @@ public function getBuyerEmailBcc(): string
return $this->buyerEmailBcc;
}

/**
* @param string $buyerEmailReplyTo
*/
public function setBuyerEmailReplyTo(string $buyerEmailReplyTo): void
{
$this->buyerEmailReplyTo = $buyerEmailReplyTo;
}

/**
* @return string
*/
public function getBuyerEmailReplyTo(): string
{
return $this->buyerEmailReplyTo;
}

/**
* @param string $email
*/
Expand Down Expand Up @@ -245,25 +277,28 @@ public function getSellerEmailBcc(): string
*
* @param Item $orderItem
*/
public function sendBuyerMail(Item $orderItem)
public function sendBuyerMail(Item $orderItem): void
{
if (empty($this->buyerEmailFrom) || empty($orderItem->getBillingAddress()->getEmail())) {
if (empty($this->getBuyerEmailFrom()) || empty($orderItem->getBillingAddress()->getEmail())) {
return;
}

$status = $orderItem->getPayment()->getStatus();

$email = GeneralUtility::makeInstance(FluidEmail::class)
->to($orderItem->getBillingAddress()->getEmail())
->from($this->buyerEmailFrom)
->from($this->getBuyerEmailFrom())
->setTemplate('Mail/' . ucfirst($status) . '/Buyer')
->format(\TYPO3\CMS\Core\Mail\FluidEmail::FORMAT_HTML)
->format(FluidEmail::FORMAT_HTML)
->assign('settings', $this->pluginSettings['settings'])
->assign('cart', $this->cart)
->assign('orderItem', $orderItem);

if ($this->buyerEmailBcc) {
$email->bcc(explode(',', $this->buyerEmailBcc));
if ($this->getBuyerEmailBcc()) {
$email->bcc(explode(',', $this->getBuyerEmailBcc()));
}
if ($this->getbuyerEmailReplyTo()) {
$email->replyTo($this->getbuyerEmailReplyTo());
}

if ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cart']['MailAttachmentsHook']) {
Expand All @@ -289,28 +324,28 @@ public function sendBuyerMail(Item $orderItem)
*
* @param Item $orderItem
*/
public function sendSellerMail(Item $orderItem)
public function sendSellerMail(Item $orderItem): void
{
if (empty($this->sellerEmailFrom) || empty($this->sellerEmailTo)) {
if (empty($this->getSellerEmailFrom()) || empty($this->getSellerEmailTo())) {
return;
}

$status = $orderItem->getPayment()->getStatus();

$email = GeneralUtility::makeInstance(FluidEmail::class)
->to($this->sellerEmailTo)
->from($this->sellerEmailFrom)
->to($this->getSellerEmailTo())
->from($this->getSellerEmailFrom())
->setTemplate('Mail/' . ucfirst($status) . '/Seller')
->format(\TYPO3\CMS\Core\Mail\FluidEmail::FORMAT_HTML)
->format(FluidEmail::FORMAT_HTML)
->assign('settings', $this->pluginSettings['settings'])
->assign('cart', $this->cart)
->assign('orderItem', $orderItem);

if ($orderItem->getBillingAddress()->getEmail()) {
$email->replyTo($orderItem->getBillingAddress()->getEmail());
}
if ($this->sellerEmailBcc) {
$bcc = explode(',', $this->sellerEmailBcc);
if ($this->getSellerEmailBcc()) {
$bcc = explode(',', $this->getSellerEmailBcc());
$email->bcc(...$bcc);
}

Expand Down
11 changes: 11 additions & 0 deletions Configuration/FlexForms/CartPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@
</config>
</TCEforms>
</settings.buyer.emailBccAddress>
<settings.buyer.emailReplyToAddress>
<TCEforms>
<label>
LLL:EXT:cart/Resources/Private/Language/locallang_db.xml:tx_cart.flexform.buyer.email_reply_to_address
</label>
<description>LLL:EXT:cart/Resources/Private/Language/locallang_db.xml:tx_cart.flexform.buyer.email_reply_to_address.description</description>
<config>
<type>input</type>
</config>
</TCEforms>
</settings.buyer.emailReplyToAddress>
</el>
</ROOT>
</sDEF>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ but also configured via TypoScript.
buyer {
fromAddress = cart.buyer.sender@extco.de
bccAddress = cart.buyer.bcc1@extco.de, cart.buyer.bcc2@extco.de
replyToAddress = cart.buyer.reply@extco.de
attachments {
1 = EXT:theme_cart/Resources/Public/Files/AGB.pdf
}
Expand Down Expand Up @@ -48,6 +49,18 @@ mail.buyer.bccAddress
Defines to which addresses the e-mail should be sent in BCC (Blind Carbon Copy).
Multiple recipients can be given separated by commas.

mail.buyer.replyToAddress
"""""""""""""""""""""""""
.. container:: table-row

Property
plugin.tx_cart.mail.buyer.replyToAddress
Data type
string
Description
Defines to which address should be used as Reply To.
This will override the ['MAIL']['defaultMailReplyToAddress'] configuration.

mail.buyer.attachments
""""""""""""""""""""""
.. container:: table-row
Expand Down
10 changes: 9 additions & 1 deletion Resources/Private/Language/de.locallang_db.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2015-02-03T15:20:00Z" product-name="cart">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2021-02-09T12:22:00Z" product-name="cart">
<header/>
<body>

Expand Down Expand Up @@ -79,6 +79,14 @@
<source>The recipients of e-mails sent to one or more e-mail addresses separated by commas and listed in the so-called BCC (Blind Carbon Copy) field will receive a copy of the sent e-mail without their address being visible to the other specified recipients. (Source: Wikipedia)</source>
<target>Die Empfänger von E-Mails an eine oder mehrere durch Kommata getrennte E-Mail-Adressen, die im sogenannten BCC-Feld (von englisch: Blind Carbon Copy, dt. sinngemäß Blindkopie) aufgeführt wurden, erhalten eine Kopie der gesendeten E-Mail, ohne dass ihre Adresse für die anderen angegebenen Empfänger sichtbar wird. (Quelle: Wikipedia)</target>
</trans-unit>
<trans-unit id="tx_cart.flexform.buyer.email_reply_to_address">
<source>Reply To email address for email to the Buyer</source>
<target>Reply To E-Mail-Adresse für E-Mail an den Käufer</target>
</trans-unit>
<trans-unit id="tx_cart.flexform.buyer.email_reply_to_address.description">
<source>The Reply To will override the default address configured in TYPO3 configuration.</source>
<target>Die Reply To E-Mail-Adresse überschreibt die im TYPO3 konfigurierte Standardantwortadresse.</target>
</trans-unit>

<trans-unit id="tx_cart.tax_class_id">
<source>Tax Class</source>
Expand Down
8 changes: 7 additions & 1 deletion Resources/Private/Language/locallang_db.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext" original="messages" date="2015-02-03T15:20:00Z" product-name="cart">
<file source-language="en" datatype="plaintext" original="messages" date="2021-02-09T12:22:00Z" product-name="cart">
<header/>
<body>

Expand Down Expand Up @@ -61,6 +61,12 @@
<trans-unit id="tx_cart.flexform.buyer.email_bcc_address.description">
<source>The recipients of e-mails sent to one or more e-mail addresses separated by commas and listed in the so-called BCC (Blind Carbon Copy) field will receive a copy of the sent e-mail without their address being visible to the other specified recipients. (Source: Wikipedia)</source>
</trans-unit>
<trans-unit id="tx_cart.flexform.buyer.email_reply_to_address">
<source>Reply To email address for email to the Buyer</source>
</trans-unit>
<trans-unit id="tx_cart.flexform.buyer.email_reply_to_address.description">
<source>The Reply To will override the default address configured in TYPO3 configuration.</source>
</trans-unit>

<trans-unit id="tx_cart.tax_class_id">
<source>Tax Class</source>
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'description' => 'Shopping Cart(s) for TYPO3',
'category' => 'plugin',
'shy' => false,
'version' => '7.0.1',
'version' => '7.1.0',
'dependencies' => '',
'conflicts' => '',
'priority' => '',
Expand Down

0 comments on commit e3396aa

Please sign in to comment.