public function emailOrderComplete($transactionInfo) { $params = Component::params(Request::getVar('option')); $items = unserialize($transactionInfo->tiItems); //print_r($items); die; // Build emails // Build order summary $summary = 'Order number: ' . $transactionInfo->tId . "\n\n"; $summary .= "\n====================\n\n"; $summary .= 'Subtotal: ' . '$' . number_format($transactionInfo->tiSubtotal, 2) . "\n"; if (!$transactionInfo->tiShipping) { $transactionInfo->tiShipping = 0; } if ($transactionInfo->tiShipping > 0) { $summary .= 'Shipping and handling: ' . '$' . number_format($transactionInfo->tiShipping, 2) . "\n"; } if (!$transactionInfo->tiTax) { $transactionInfo->tiTax = 0; } if ($transactionInfo->tiDiscounts > 0 || $transactionInfo->tiShippingDiscount > 0) { $summary .= 'Discounts: ' . '$' . number_format($transactionInfo->tiDiscounts + $transactionInfo->tiShippingDiscount, 2) . "\n"; } if ($transactionInfo->tiTax > 0) { $summary .= 'Tax: ' . '$' . number_format($transactionInfo->tiTax, 2) . "\n"; } $summary .= 'Total: ' . '$' . number_format($transactionInfo->tiTotal, 2) . "\n"; if (!empty($transactionInfo->tiShippingToFirst)) { $summary .= "\n\nShipping address:"; $summary .= "\n--------------------\n"; $summary .= $transactionInfo->tiShippingToFirst . ' ' . $transactionInfo->tiShippingToLast . "\n"; $summary .= $transactionInfo->tiShippingAddress . "\n"; $summary .= $transactionInfo->tiShippingCity . ', ' . $transactionInfo->tiShippingState . ' ' . $transactionInfo->tiShippingZip . "\n"; } $summary .= "\n\nItems ordered:"; $summary .= "\n--------------------\n"; require_once PATH_CORE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php'; $warehouse = new \Components\Storefront\Models\Warehouse(); foreach ($items as $k => $item) { $itemInfo = $item['info']; $cartInfo = $item['cartInfo']; $itemMeta = $item['meta']; //print_r($item); die; $productType = $warehouse->getProductTypeInfo($itemInfo->ptId)['ptName']; // If course, generate a link to the course $action = false; if ($productType == 'Course') { $action = ' Go to the course page at: ' . ($action .= Route::url('index.php?option=com_courses', true, -1) . $itemMeta['courseId'] . '/' . $itemMeta['offeringId']); } elseif ($productType == 'Software Download') { $action = ' Download at: ' . ($action .= Route::url('index.php?option=com_cart', true, -1) . 'download/' . $transactionInfo->tId . '/' . $itemInfo->sId); if (isset($itemMeta['serial']) && !empty($itemMeta['serial'])) { $action .= "\n\t"; $action .= " Serial number: " . $itemMeta['serial']; } } $summary .= "{$cartInfo->qty} x "; $summary .= "{$itemInfo->pName}"; if (!empty($item['options'])) { $summary .= '('; $optionCount = 0; foreach ($item['options'] as $option) { if ($optionCount) { $summary .= ', '; } $summary .= $option; $optionCount++; } $summary .= ')'; } $summary .= ' @ ' . '$' . number_format($itemInfo->sPrice, 2); if ($action) { $summary .= "\n\t"; $summary .= $action; } $summary .= "\n"; } //print_r($summary); die; // Get message plugin JPluginHelper::importPlugin('xmessage'); // "from" info $from = array(); $from['name'] = Config::get('sitename'); $from['email'] = Config::get('mailfrom'); // Email to admin $adminEmail = "There is a new online store order: \n\n"; $adminEmail .= $summary; // Admin email $to = array($params->get('storeAdminId')); Event::trigger('onSendMessage', array('store_notifications', 'New order at ' . $from['name'], $adminEmail, $from, $to, '', null, '', 0, true)); // Email to client $clientEmail = 'Thank you for your order at ' . Config::get('sitename') . "!\n\n"; $clientEmail .= $summary; require_once dirname(dirname(__DIR__)) . DS . 'models' . DS . 'Cart.php'; $to = array(\Components\Cart\Models\Cart::getCartUser($transactionInfo->crtId)); Event::trigger('onSendMessage', array('store_notifications', 'Your order at ' . $from['name'], $clientEmail, $from, $to, '', null, '', 0, true)); // Email notification extra $notifyTo = $params->get('sendNotificationTo'); if (!empty($notifyTo)) { $notifyTo = explode(',', str_replace(' ', '', $notifyTo)); $notifyEmail = 'There is a new online store order at ' . Config::get('sitename') . "\n\n"; $notifyEmail .= $summary; // Plain text email $eview = new \Hubzero\Component\View(array('name' => 'emails', 'layout' => 'order_notify')); $eview->option = $this->_option; $eview->controller = $this->_controller; $eview->message = $notifyEmail; $plain = $eview->loadTemplate(); $plain = str_replace("\n", "\r\n", $plain); $message = new \Hubzero\Mail\Message(); $message->setSubject('ORDER NOTIFICATION: New order at ' . $from['name']); $message->addFrom(Config::get('mailfrom'), Config::get('sitename')); $message->addPart($plain, 'text/plain'); foreach ($notifyTo as $email) { if (\Hubzero\Utility\Validate::email($email)) { $message->addTo($email); } } $message->setBody($plain); $message->send(); } }
/** * Send a message to a user * * @param array $from Message 'from' data (e.g., name, address) * @param object $xmessage The message to send * @param object $user User to send the message to * @param string $action Messaging method (e.g., email, smstxt, etc.) * @return boolean True if message was sent */ public function onMessage($from, $xmessage, $user, $action) { //make sure were supposed to be performing this action if ($this->onMessageMethods() != $action) { return true; } //check to make sure users account is confirmed if ($user->get('activation') <= 0) { return false; } //if we dont have an email stop if (!$user->get('email')) { return false; } // if we dont have a from set the use site from name and email if (!isset($from['name']) || $from['name'] == '') { $from['name'] = Config::get('sitename') . ' Administrator'; } if (!isset($from['email']) || $from['email'] == '') { $from['email'] = Config::get('mailfrom'); } $name = $user->get('name'); if (preg_match('/[А-Яа-яЁё]/u', $name)) { $name = $user->get('email'); } $message = new \Hubzero\Mail\Message(); $message->setSubject(Config::get('sitename') . ' ' . $xmessage->subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $name); // In case a different reply to email address is specified if (array_key_exists('replytoemail', $from)) { $replytoname = isset($from['replytoname']) && $from['replytoname'] != '' ? $from['replytoname'] : $from['name']; if (preg_match('/[А-Яа-яЁё]/u', $replytoname)) { $replytoname = $from['replytoemail']; } $message->addReplyTo($from['replytoemail'], $replytoname); } else { if (preg_match('/[А-Яа-яЁё]/u', $from['name'])) { $from['name'] = $from['email']; } $message->addReplyTo($from['email'], $from['name']); } //set mail additional args (mail return path - used for bounces) $message->addHeader('X-Component', $xmessage->component)->addHeader('X-Component-Object', $xmessage->type); // Want to add some extra headers? We put them into the from array // If none are there, this breaks nothing if (array_key_exists('xheaders', $from)) { // The xheaders array has name and value pairs foreach ($from['xheaders'] as $n => $v) { $message->addHeader($n, $v); } } $m = $xmessage->get('message'); if (is_array($m)) { if (isset($m['attachments'])) { if (!is_array($m['attachments'])) { $m['attachments'] = array($m['attachments']); } foreach ($m['attachments'] as $path) { if (preg_match("/\\.(bmp|gif|jpg|jpe|jpeg|png)\$/i", $path)) { $file = basename($path); $m['multipart'] = preg_replace('/<a class="img" data\\-filename="' . str_replace('.', '\\.', $file) . '" href="(.*?)"\\>(.*?)<\\/a>/i', '<img src="' . $message->getEmbed($path) . '" alt="" />', $m['multipart']); } else { $message->addAttachment($path); } } } $message->addPart($m['plaintext'], 'text/plain')->addPart($m['multipart'], 'text/html'); } else { $message->setBody($m); } // send mail if ($message->send()) { return true; } return false; }