[英]Sending email notifications depending on customer group - opencart
I have a question - Im using OC 2.2.0. 我有一个问题-我正在使用OC 2.2.0。 I have two customer groups 1 and 4. I was wondering if it is possible to send new order notifications emails to different admin email addresses depending on customer group to which a buyer(customer) belongs?
我有两个客户组1和4。我想知道是否可以根据买家(客户)所属的客户组将新的订单通知电子邮件发送到不同的管理员电子邮件地址? Meaning- if customer belongs to group 1, send to mail1@mail.com(which belongs to admin 1) and if the customer belongs to group 4, send notification mail to mail2@mail.com(which belongs to admin 2.
含义-如果客户属于组1,则发送到mail1@mail.com(属于管理员1),如果客户属于组4,则将通知邮件发送到mail2@mail.com(属于管理员2)。
I tried adding to model/checkout/order.php
the following: 我尝试将以下内容添加到
model/checkout/order.php
中:
if($customer_group_id != 1) {
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo(array(0 => 'somemail@gmail.com'));
$mail->setFrom($this->config->get('config_email'));
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
$mail->setHtml($this->load->view('mail/order', $data));
$mail->setText($text);
$mail->send();
// Send to additional alert emails
$emails = explode(',', $this->config->get('config_mail_alert'));
foreach ($emails as $email) {
if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$mail->setTo($email);
$mail->send();
}
}
}
if($customer_group_id != 4) {
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
$mail->setTo(array(0 => 'somemail@gmail.com'));
$mail->setFrom($this->config->get('config_email'));
$mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
$mail->setHtml($this->load->view('mail/order', $data));
$mail->setText($text);
$mail->send();
// Send to additional alert emails
$emails = explode(',', $this->config->get('config_mail_alert'));
foreach ($emails as $email) {
if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) {
$mail->setTo($email);
$mail->send();
}
}
}
but this always sends mail to both email addresses. 但这总是将邮件发送到两个电子邮件地址。 I guess it doesn't recognise my customer groups.
我猜它无法识别我的客户群。 Where else should I define them?
我还应该在哪里定义它们? I didn't put real mail address in this example, obviously.
显然,我没有在此示例中输入真实的邮件地址。 Any suggestions?
有什么建议么?
As I suspected, I just needed to define customer groups in the same file (model/checkout/order.php)
like this: 正如我所怀疑的,我只需要在同一文件
(model/checkout/order.php)
定义客户组,如下所示:
if (isset($this->request->get['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->get['customer_group_id'], $this->config->get('config_customer_group_display'))) {
$customer_group_id = $this->request->get['customer_group_id'];
} else {
$customer_group_id = $this->config->get('config_customer_group_id');
}
I hope this helps someone. 我希望这可以帮助别人。 Cheers
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.