protected static function sendEmail($n, $data) { $general = wa('shop')->getConfig()->getGeneralSettings(); if (!empty($n['from'])) { $from = $n['from']; } else { $from = $general['email']; } /** * @var waContact $customer */ $customer = $data['customer']; if ($n['to'] == 'customer') { $email = $customer->get('email', 'default'); if (!$email) { return; } $to = array($email); $log = sprintf(_w("Notification <strong>%s</strong> sent to customer."), $n['name']); } elseif ($n['to'] == 'admin') { if (!$general['email']) { return; } $to = array($general['email']); $log = sprintf(_w("Notification <strong>%s</strong> sent to store admin."), $n['name']); } else { $to = explode(',', $n['to']); $log = sprintf(_w("Notification <strong>%s</strong> sent to %s."), $n['name'], $n['to']); } $view = wa()->getView(); foreach (array('shipping', 'billing') as $k) { $address = shopHelper::getOrderAddress($data['order']['params'], $k); $formatter = new waContactAddressOneLineFormatter(array('image' => false)); $address = $formatter->format(array('data' => $address)); $view->assign($k . '_address', $address['value']); } $order_id = $data['order']['id']; $data['order']['id'] = shopHelper::encodeOrderId($order_id); $view->assign('order_url', wa()->getRouteUrl('/frontend/myOrderByCode', array('id' => $order_id, 'code' => $data['order']['params']['auth_code']), true)); $view->assign($data); $subject = $view->fetch('string:' . $n['subject']); $body = $view->fetch('string:' . $n['body']); $message = new waMailMessage($subject, $body); $message->setTo($to); if ($n['to'] == 'admin') { if ($customer_email = $customer->get('email', 'default')) { $message->addReplyTo($customer_email); } } if ($from) { $message->setFrom($from, $general['name']); } if ($message->send()) { $order_log_model = new shopOrderLogModel(); $order_log_model->add(array('order_id' => $order_id, 'contact_id' => null, 'action_id' => '', 'text' => '<i class="icon16 email"></i> ' . $log, 'before_state_id' => $data['order']['state_id'], 'after_state_id' => $data['order']['state_id'])); } }