From 0682a019650f11462848b59459110c746052d14c Mon Sep 17 00:00:00 2001 From: Gabor Pipicz Date: Fri, 4 Mar 2016 15:09:10 +0100 Subject: [PATCH 1/2] [*] MO : Allow more customer attributes in templates of MailAlert module We've needed to display a special customer attribute in order notification (a customer number, applied by a third party module). The proposed solution is to iterate on all defined fields of the class Customer, add each with a prefix 'customer_'. --- mailalerts.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mailalerts.php b/mailalerts.php index 75aebba..dbe9aaf 100644 --- a/mailalerts.php +++ b/mailalerts.php @@ -404,6 +404,13 @@ public function hookActionValidateOrder($params) '{message}' => $message ); + foreach(Customer::$definition['fields'] as $key => $value) { + if(!isset($customer->$key)) { + continue; + } + $template_vars['{customer_'.$key.'}'] = $customer->$key; + } + // Shop iso $iso = Language::getIsoById((int)Configuration::get('PS_LANG_DEFAULT')); @@ -785,6 +792,13 @@ public function hookActionOrderReturn($params) '{message}' => Tools::purifyHTML($params['orderReturn']->question), ); + foreach(Customer::$definition['fields'] as $key => $value) { + if(!isset($customer->$key)) { + continue; + } + $template_vars['{customer_'.$key.'}'] = $customer->$key; + } + // Send 1 email by merchant mail, because Mail::Send doesn't work with an array of recipients $merchant_mails = explode(self::__MA_MAIL_DELIMITOR__, $this->merchant_mails); foreach ($merchant_mails as $merchant_mail) @@ -856,6 +870,14 @@ public function hookActionOrderEdited($params) '{order_name}' => $order->getUniqReference() ); + $customer = $order->getCustomer(); + foreach(Customer::$definition['fields'] as $key => $value) { + if(!isset($customer->$key)) { + continue; + } + $template_vars['{customer_'.$key.'}'] = $customer->$key; + } + Mail::Send( (int)$order->id_lang, 'order_changed', From 2339047f520bf932bd9d88e87f4b516c2d3a363a Mon Sep 17 00:00:00 2001 From: Gabor Pipicz Date: Fri, 4 Mar 2016 15:16:24 +0100 Subject: [PATCH 2/2] [-] MO : Fix variable naming at 0682a019650f11462848b59459110c746052d14c --- mailalerts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailalerts.php b/mailalerts.php index dbe9aaf..3948293 100644 --- a/mailalerts.php +++ b/mailalerts.php @@ -875,7 +875,7 @@ public function hookActionOrderEdited($params) if(!isset($customer->$key)) { continue; } - $template_vars['{customer_'.$key.'}'] = $customer->$key; + $data['{customer_'.$key.'}'] = $customer->$key; } Mail::Send(