From 91b934212baae1948c2a3cf9fcb754cb30ba8e3b Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Thu, 21 Sep 2023 14:29:38 +0200 Subject: [PATCH 1/5] #15 Fix: Sender/Recipient was taken from default config --- Helper/Email.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Helper/Email.php b/Helper/Email.php index 2376eb0..c6b38b2 100644 --- a/Helper/Email.php +++ b/Helper/Email.php @@ -112,8 +112,8 @@ public function send(string $to, array $vars, int $storeId = 0) 'store' => $storeId, ]); $this->transportBuilder->addTo($to); - $this->transportBuilder->addBcc($this->getRecipientAddress()); - $this->transportBuilder->setFromByScope($this->getFrom()); + $this->transportBuilder->addBcc($this->getRecipientAddress($storeId)); + $this->transportBuilder->setFromByScope($this->getFrom($storeId)); $this->transportBuilder->setTemplateVars($vars); $this->transportBuilder->getTransport()->sendMessage(); $this->inlineTranslate->resume(); @@ -122,35 +122,35 @@ public function send(string $to, array $vars, int $storeId = 0) /** * @return mixed */ - private function getRecipientAddress() + private function getRecipientAddress(int $storeId = 0) { - return $this->getContactConfig('general/send_to') ?? $this->getConfig('trans_email/ident_sales/email'); + return $this->getContactConfig('general/send_to', $storeId) ?? $this->getConfig('trans_email/ident_sales/email', $storeId); } /** * @return array */ - private function getFrom() + private function getFrom(int $storeId = 0) { return [ - 'name' => $this->getFromName(), - 'email' => $this->getFromAddress(), + 'name' => $this->getFromName($storeId), + 'email' => $this->getFromAddress($storeId), ]; } /** * @return mixed */ - private function getFromAddress() + private function getFromAddress(int $storeId = 0) { - return $this->getContactConfig('general/send_from') ?? $this->getConfig('trans_email/ident_sales/email'); + return $this->getContactConfig('general/send_from', $storeId) ?? $this->getConfig('trans_email/ident_sales/email', $storeId); } /** * @return mixed */ - private function getFromName() + private function getFromName(int $storeId = 0) { - return $this->getContactConfig('general/send_from_name') ?? $this->getConfig('trans_email/ident_sales/name'); + return $this->getContactConfig('general/send_from_name', $storeId) ?? $this->getConfig('trans_email/ident_sales/name', $storeId); } } From 3af2cfee6339fdd1fda24c6182664aeacd2a30c8 Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Thu, 21 Sep 2023 14:41:39 +0200 Subject: [PATCH 2/5] #13 Add all_fields_html field to include all fields easily --- Helper/Email.php | 6 +++++- view/frontend/email/sy_contact_general_email_template.html | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Helper/Email.php b/Helper/Email.php index c6b38b2..d7b2477 100644 --- a/Helper/Email.php +++ b/Helper/Email.php @@ -83,13 +83,17 @@ public function receive(Request $request, $storeId = 0) */ public function toVars(array $array) { + $allFieldsHtml = ''; $vars = []; if (is_array($array) && count($array) > 0) { foreach ($array as $field) { - $vars[$field['key']] = $field['value']; + $value = is_array($field['value']) ? implode(', ', $field['value']) : (string) $field['value']; + $vars[$field['key']] = $value; + $allFieldsHtml .= sprintf('%s: %s
', htmlspecialchars($field['label']), htmlspecialchars($value)); } } + $vars['_all_fields_html'] = $allFieldsHtml; return $vars; } diff --git a/view/frontend/email/sy_contact_general_email_template.html b/view/frontend/email/sy_contact_general_email_template.html index 7d28feb..cba39f7 100644 --- a/view/frontend/email/sy_contact_general_email_template.html +++ b/view/frontend/email/sy_contact_general_email_template.html @@ -1,2 +1,2 @@ -Customer Message: {{var message}}
\ No newline at end of file +{{var _all_fields_html|raw}} From ed255a4cdfefc820a985322256f48cd74acf6825 Mon Sep 17 00:00:00 2001 From: Alexander Menk Date: Thu, 21 Sep 2023 14:51:15 +0200 Subject: [PATCH 3/5] Fix: multicheckbox triggered wrong checkbox (duplicate ids) --- Helper/Email.php | 2 +- view/frontend/templates/form.phtml | 84 +++++++++++++++--------------- 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Helper/Email.php b/Helper/Email.php index d7b2477..6994ce3 100644 --- a/Helper/Email.php +++ b/Helper/Email.php @@ -89,7 +89,7 @@ public function toVars(array $array) foreach ($array as $field) { $value = is_array($field['value']) ? implode(', ', $field['value']) : (string) $field['value']; $vars[$field['key']] = $value; - $allFieldsHtml .= sprintf('%s: %s
', htmlspecialchars($field['label']), htmlspecialchars($value)); + $allFieldsHtml .= sprintf('%s: %s
', htmlspecialchars($field['label']), htmlspecialchars($value)) . PHP_EOL; } } diff --git a/view/frontend/templates/form.phtml b/view/frontend/templates/form.phtml index 5b2cc24..1c5bf2b 100644 --- a/view/frontend/templates/form.phtml +++ b/view/frontend/templates/form.phtml @@ -7,65 +7,67 @@ ?> getFields(); ?> 0): ?> -
- + +
- +
- +
-
+
+ for="getData('key'); ?>">getData('label'); ?>
getData('field_type'), ['text', 'email'])): ?> - + getData('field_type') == 'textarea'): ?> - + getData('field_type') == 'checkbox'): ?> - -