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; }
function orderstatesave() { $app = JFactory::getApplication(); $id = $app->input->getInt('id', 0); $order_state_id = $app->input->getInt('order_state_id', 0); $notify_customer = $app->input->getInt('notify_customer', 0); if (isset($order_state_id) && $order_state_id > 0) { require_once JPATH_ADMINISTRATOR . '/components/com_j2store/models/orderstatuses.php'; $os_model = new J2StoreModelOrderstatuses(); $order_state = $os_model->getOrderStateByID($order_state_id)->orderstatus_name; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_j2store/tables'); $order = JTable::getInstance('Orders', 'Table'); $order->load($id); if ($order->id == $id) { //lets change the status $order->order_state = $order_state; $order->order_state_id = $order_state_id; if ($order->store()) { $msg = JText::_('J2STORE_ORDER_STATUS_UPDATE_SUCCESSFUL'); if (isset($notify_customer) && $notify_customer == 1) { require_once JPATH_SITE . '/components/com_j2store/helpers/orders.php'; J2StoreOrdersHelper::sendUserEmail($order->user_id, $order->order_id, $order->transaction_status, $order->order_state, $order->order_state_id); } else { require_once JPATH_ADMINISTRATOR . '/components/com_j2store/library/inventory.php'; J2StoreInventory::setInventory($order->id, $order_state_id); } } else { $msg = JText::_('J2STORE_ORDER_STATUS_UPDATE_FAILED'); } } else { $msg = JText::_('J2STORE_ORDER_STATUS_UPDATE_FAILED'); } } else { $msg = JText::_('J2STORE_CHOOSE_AN_ORDER_STATUS'); } $link = 'index.php?option=com_j2store&view=orders&task=view&id=' . $order->id; $return = $app->input->getString('return'); if (isset($return) && !empty($return)) { $json = array(); $json['success']['link'] = 'index.php?option=com_j2store&view=orders'; echo json_encode($json); $app->close(); } else { $this->setRedirect($link, $msg); } }