Пример #1
0
 public static function sendUserEmail($user_id, $order_id, $payment_status, $order_status, $order_state_id)
 {
     $mainframe = JFactory::getApplication();
     $config = JFactory::getConfig();
     $j2params = JComponentHelper::getParams('com_j2store');
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $sitename = $config->get('sitename');
     } else {
         $sitename = $config->getValue('config.sitename');
     }
     //now get the order table's id based on order id
     $order = J2StoreOrdersHelper::_getOrderKey($order_id);
     //inventory
     //TODO::move this function to the plugin.
     require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/inventory.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_j2store/version.php';
     J2StoreInventory::setInventory($order->id, $order_state_id);
     $mainframe->triggerEvent('onJ2StoreBeforeOrderNotification', array($order));
     //now get the receipient
     $recipient = J2StoreOrdersHelper::_getRecipient($order->order_id);
     //check for email templates. If it is there, get the orderemail from there
     require_once JPATH_SITE . '/components/com_j2store/helpers/email.php';
     $emailHelper = new J2StoreHelperEmail();
     $orderObj = self::getOrder($order->id);
     if (count($emailHelper->getEmailTemplates($orderObj)) && J2STORE_PRO == 1) {
         $mailer = $emailHelper->getEmail($orderObj);
     } else {
         if ($user_id && empty($recipient->billing_first_name)) {
             $recipient->name = JFactory::getUser($user_id)->name;
         } else {
             $recipient->name = $recipient->billing_first_name . ' ' . $recipient->billing_last_name;
         }
         $body = J2StoreOrdersHelper::_getHtmlFormatedOrder($order->id, $user_id);
         $subject = JText::sprintf('J2STORE_ORDER_USER_EMAIL_SUB', $recipient->name, $sitename);
         $mailer = clone JFactory::getMailer();
         $mailer->IsHTML(true);
         $mailer->CharSet = 'UTF-8';
         $mailer->setSubject($subject);
         $mailer->setBody($body);
     }
     $admin_emails = $j2params->get('admin_email');
     $admin_emails = explode(',', $admin_emails);
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $mailfrom = $j2params->get('emails_defaultemail', $config->get('mailfrom'));
         $fromname = $j2params->get('emails_defaultname', $config->get('fromname'));
     } else {
         $mailfrom = $j2params->get('emails_defaultemail', $config->getValue('config.mailfrom'));
         $fromname = $j2params->get('emails_defaultname', $config->getValue('config.fromname'));
     }
     //send email
     if ($recipient) {
         $mailer->addRecipient($recipient->user_email);
         //	$mailer->addBCC( $admin_emails );
         $mailer->setSender(array($mailfrom, $fromname));
         $mailer->send();
         $mailer = null;
     }
     if ($admin_emails) {
         if (count($emailHelper->getEmailTemplates($orderObj)) && J2STORE_PRO == 1) {
             $mailer = $emailHelper->getEmail($orderObj);
         } else {
             $mailer = clone JFactory::getMailer();
             $mailer->IsHTML(true);
             $mailer->CharSet = 'UTF-8';
             $mailer->setSubject($subject);
             $mailer->setBody($body);
         }
         $mailer->addRecipient($admin_emails);
         $mailer->setSender(array($mailfrom, $fromname));
         $mailer->send();
         $mailer = null;
     }
     $mainframe->triggerEvent('onJ2StoreAfterOrderNotification', array($order));
     return true;
 }