'ECommerce_Order_Admin_'], null, 'url') . '?action=view&id=' . (!empty($data['orderId']) ? $data['orderId'] : $data['id']); } static::_sendNotification($data, $adminEmails); return true; } /** * Send notification to user * * @static * @param array $data * @param string $suffix * @return App_ECommerce_Order_MailAdapter */ public static function sendUserNotification($data, $suffix = '') { $userEmail = $data['billingEmail']; if (filter_var($userEmail, FILTER_VALIDATE_EMAIL)) { static::$_settingsPrefix = static::$_baseSettingsPrefix . $suffix . 'UserEmail'; if (!static::_isUserLoggedIn() && !$data['userId']) { $data['link'] = Qs_SiteMap::findFirst(null, ['type' => 'ECommerce_Order_GuestView_'], null, 'url') . '/' . $data['accessCode']; } else { if (empty($data['link'])) { $data['link'] = Qs_SiteMap::findFirst(null, ['type' => 'ECommerce_Order_'], null, 'url') . '/view/' . (!empty($data['orderId']) ? $data['orderId'] : $data['id']); } } static::_sendNotification($data, $userEmail); } return true; } protected static function _sendNotification($data, $to) { $body = App_Settings_Obj::get(static::$_settingsPrefix . 'Body'); if (empty($to) || empty($body)) { return false; } $subject = App_Settings_Obj::get(static::$_settingsPrefix . 'Subject'); $from = App_Settings_Obj::getEmailFrom(static::$_settingsPrefix . 'From'); if (!isset($data['link']) && false !== ($link = Qs_SiteMap::findFirst(null, ['type' => 'User\\Login\\'], null, 'url')) ) { $data['link'] = $link; } foreach ($data as $field => $value) { if (null === $value || is_scalar($value)) { $body = str_replace('{' . $field . '}', (string) $value, $body); } } return static::sendMail(compact('subject', 'from', 'to', 'body')); } /** * Send mail * * @static * @param array $options * @return bool * @throws Qs_ViewController_Exception */ public static function sendMail($options) { $requiredOptions = ['from', 'to', 'subject', 'body']; $diff = array_diff_key(array_combine($requiredOptions, array_fill(0, count($requiredOptions), '')), $options); if (!empty($diff)) { throw new Qs_ViewController_Exception('App_ECommerce_Order_MailAdapter::sendMail. Missed required options: ' . implode(', ', array_keys($diff))); } $from = $to = $subject = $body = ''; extract($options); $mail = new Qs_Mail(); $mail->setFrom($from); $mail->setSubject($subject); Qs_Mail::cutImageBaseUrl($body, constant('BASE_URL')); $mail->setHtml($body, null, constant('WWW_PATH')); $mail->addTo($to); return $mail->send(); } protected static function _isUserLoggedIn() { /** @var Qs_Doc $doc */ $doc = Zend_Registry::get('doc'); /** @var Qs_Auth $auth */ $auth = $doc->getAuth(); if ('App\\User\\Auth' == get_class($auth)) { return $auth->isLoggedIn(); } return false; } }