Example #1
0
 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);
     // $status_values = array(1 => JText::_('K2STORE_Confirmed'), 3 => JText::_('K2STORE_Failed'), 4 => JText::_('K2STORE_Pending'));
     if (isset($order_state_id) && $order_state_id > 0) {
         require_once JPATH_ADMINISTRATOR . '/components/com_k2store/models/orderstatuses.php';
         $os_model = new K2StoreModelOrderstatuses();
         $order_state = $os_model->getOrderStateByID($order_state_id)->orderstatus_name;
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2store/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::_('K2STORE_ORDER_STATUS_UPDATE_SUCCESSFUL');
                 if (isset($notify_customer) && $notify_customer == 1) {
                     require_once JPATH_SITE . '/components/com_k2store/helpers/orders.php';
                     K2StoreOrdersHelper::sendUserEmail($order->user_id, $order->order_id, $order->transaction_status, $order->order_state, $order->order_state_id);
                 } else {
                     require_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/inventory.php';
                     K2StoreInventory::setInventory($order->id, $order_state_id);
                 }
             } else {
                 $msg = JText::_('K2STORE_ORDER_STATUS_UPDATE_FAILED');
             }
         } else {
             $msg = JText::_('K2STORE_ORDER_STATUS_UPDATE_FAILED');
         }
     } else {
         $msg = JText::_('K2STORE_CHOOSE_AN_ORDER_STATUS');
     }
     $link = 'index.php?option=com_k2store&view=orders&task=view&id=' . $order->id;
     $this->setRedirect($link, $msg);
 }
Example #2
0
 public static function sendUserEmail($user_id, $order_id, $payment_status, $order_status, $order_state_id)
 {
     $mainframe = JFactory::getApplication();
     jimport('joomla.filesystem.file');
     // grab config settings for sender name and email
     $config = JFactory::getConfig();
     $k2store_params = JComponentHelper::getParams('com_k2store');
     $k2params = JComponentHelper::getParams('com_k2');
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $mailfrom = $k2store_params->get('emails_defaultemail', $config->get('mailfrom'));
         $fromname = $k2store_params->get('emails_defaultname', $config->get('fromname'));
     } else {
         $mailfrom = $k2store_params->get('emails_defaultname', $config->getValue('config.mailfrom'));
         $fromname = $k2store_params->get('emails_defaultname', $config->getValue('config.fromname'));
     }
     $sitename = $k2store_params->get('sitename', $mainframe->getCfg('sitename'));
     $siteurl = $k2store_params->get('siteurl', JURI::root());
     //now get the order table's id based on order id
     $id = self::_getOrderKey($order_id);
     //inventory
     //TODO::move this function to the plugin.
     require_once JPATH_ADMINISTRATOR . '/components/com_k2store/library/inventory.php';
     K2StoreInventory::setInventory($id, $order_state_id);
     //now get the receipient
     $recipient = self::_getRecipient($order_id);
     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;
     }
     $html = self::_getHtmlFormatedOrder($id, $user_id);
     $mailer = JFactory::getMailer();
     $mode = 1;
     $subject = JText::sprintf('K2STORE_ORDER_USER_EMAIL_SUB', $recipient->name, $sitename);
     $tags = array('[ORDER_ID]' => $id);
     foreach ($tags as $key => $value) {
         $subject = str_replace($key, $id, $subject);
     }
     $msg = '';
     $msg .= $html;
     //send attachments as well
     //allow_attachment_downloads
     //attachements
     //send attachments, only when the order state is confirmed and attachments are allowed
     if ($k2store_params->get('allow_attachment_downloads') && $order_state_id == 1) {
         $attachments = self::getAttachments($order_id);
         $path = $k2params->get('attachmentsFolder', NULL);
         if (is_null($path)) {
             $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments';
         } else {
             $savepath = $path;
         }
         if (count($attachments) > 0) {
             $msg .= '<br />----------------------------------------------------------------------------------------------------------- <br />';
             $msg .= JText::_('K2STORE_ATTACHED_FILES_TO_THIS_EMAIL') . ': <br />';
             foreach ($attachments as $attachment) {
                 $myfile = trim($attachment->filename);
                 $att = $savepath . DS . $myfile;
                 if (JFile::exists($att)) {
                     $msg .= 'File: ' . $myfile . '<br />';
                     $mailer->addAttachment($att);
                 }
             }
             //foreach
         }
         //if count
     }
     $admin_emails = trim($k2store_params->get('admin_email'));
     $admin_emails = explode(',', $admin_emails);
     //send email
     if ($recipient) {
         $mailer->addRecipient($recipient->user_email);
         //   $mailer->addCC( $config->get('admin_email'));
         //$mailer->addCC( $admin_emails );
         $mailer->setSubject($subject);
         $mailer->setBody($msg);
         $mailer->IsHTML($mode);
         $mailer->setSender(array($mailfrom, $fromname));
         $mailer->send();
     }
     if ($admin_emails) {
         $mailer = JFactory::getMailer();
         $mailer->addRecipient($admin_emails);
         $mailer->setSubject($subject);
         $mailer->setBody($msg);
         $mailer->IsHTML($mode);
         $mailer->setSender(array($mailfrom, $fromname));
         $mailer->send();
     }
     return true;
 }