Exemplo n.º 1
0
 public function addOrderHistory($order_id, $data)
 {
     $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '" . (int) $data['order_status_id'] . "', date_modified = NOW() WHERE order_id = '" . (int) $order_id . "'");
     $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int) $order_id . "', order_status_id = '" . (int) $data['order_status_id'] . "', notify = '" . (isset($data['notify']) ? (int) $data['notify'] : 0) . "', comment = '" . $this->db->escape(strip_tags($data['comment'])) . "', date_added = NOW()");
     $order_info = $this->getOrder($order_id);
     // Send out any gift voucher mails
     if ($this->config->get('config_complete_status_id') == $data['order_status_id']) {
         $this->load->model('sale/voucher');
         $results = $this->getOrderVouchers($order_id);
         foreach ($results as $result) {
             $this->model_sale_voucher->sendVoucher($result['voucher_id']);
         }
     }
     if ($data['notify']) {
         $language = new Language($order_info['language_directory']);
         $language->load($order_info['language_filename']);
         $language->load('mail/order');
         $subject = sprintf($language->get('text_subject'), $order_info['store_name'], $order_id);
         $message = $language->get('text_order') . ' ' . $order_id . "\n";
         $message .= $language->get('text_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n\n";
         $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int) $data['order_status_id'] . "' AND language_id = '" . (int) $order_info['language_id'] . "'");
         if ($order_status_query->num_rows) {
             $message .= $language->get('text_order_status') . "\n";
             $message .= $order_status_query->row['name'] . "\n\n";
         }
         if ($order_info['customer_id']) {
             $message .= $language->get('text_link') . "\n";
             $message .= html_entity_decode($order_info['store_url'] . 'index.php?route=account/order/info&order_id=' . $order_id, ENT_QUOTES, 'UTF-8') . "\n\n";
         }
         if ($data['comment']) {
             $message .= $language->get('text_comment') . "\n\n";
             $message .= strip_tags(html_entity_decode($data['comment'], ENT_QUOTES, 'UTF-8')) . "\n\n";
         }
         $message .= $language->get('text_footer');
         $mail = new Mail();
         $mail->protocol = $this->config->get('config_mail_protocol');
         $mail->parameter = $this->config->get('config_mail_parameter');
         $mail->hostname = $this->config->get('config_smtp_host');
         $mail->username = $this->config->get('config_smtp_username');
         $mail->password = $this->config->get('config_smtp_password');
         $mail->port = $this->config->get('config_smtp_port');
         $mail->timeout = $this->config->get('config_smtp_timeout');
         $mail->setTo($order_info['email']);
         $mail->setFrom($this->config->get('config_email'));
         $mail->setSender($order_info['store_name']);
         $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'));
         $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
         $mail->send();
     }
     // start SMS Module
     if ($data['notifysms'] && $this->config->get('rajasmsindo_statussms')) {
         $language = new Language($order_info['language_directory']);
         $language->load($order_info['language_filename']);
         $language->load('module/rajasmsindo');
         $message = sprintf($language->get('text_subject'), $order_info['store_name'], $order_id) . "\n";
         $message .= $language->get('text_order') . ' ' . $order_id . "\n";
         $message .= $language->get('text_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n";
         $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int) $data['order_status_id'] . "' AND language_id = '" . (int) $order_info['language_id'] . "'");
         if ($order_status_query->num_rows) {
             $message .= $language->get('text_order_status') . "\n";
             $message .= $order_status_query->row['name'] . "\n";
         }
         if ($order_info['customer_id']) {
             $message .= $language->get('text_link') . "\n";
             $message .= html_entity_decode($order_info['store_url'] . 'index.php?route=account/order/info&order_id=' . $order_id, ENT_QUOTES, 'UTF-8') . "\n";
         }
         if ($data['comment']) {
             $message .= $language->get('text_comment') . "\n";
             $message .= strip_tags(html_entity_decode($data['comment'], ENT_QUOTES, 'UTF-8')) . "\n\n";
         }
         $message .= $language->get('text_footer');
         $sms = new sms();
         $sms->key = $this->config->get('rajasmsindo_key');
         $sms->phone = $this->config->get('rajasmsindo_smsphone');
         $sms->username = $this->config->get('rajasmsindo_user');
         $sms->password = $this->config->get('rajasmsindo_password');
         $sms->smsmode = $this->config->get('rajasmsindo_smsmode');
         $sms->modem = $this->config->get('rajasmsindo_modem');
         $sms->setTo($data['telephone']);
         $sms->setText($message);
         $sms->send();
     }
     // end SMS Module
     $this->load->model('payment/amazon_checkout');
     $this->model_payment_amazon_checkout->orderStatusChange($order_id, $data);
 }
Exemplo n.º 2
0
 public function send()
 {
     $this->load->language('module/rajasmsmassindo');
     $json = array();
     if ($this->request->server['REQUEST_METHOD'] == 'POST') {
         if (!$this->user->hasPermission('modify', 'module/rajasmsmassindo')) {
             $json['error']['warning'] = $this->language->get('error_permission');
         }
         if (!$this->request->post['message']) {
             $json['error']['message'] = $this->language->get('error_message');
         }
         if (!$this->config->get('rajasmsindo_statussms')) {
             $json['error']['message'] = $this->language->get('error_disabled');
         }
         if (!$json) {
             $this->load->model('setting/store');
             $store_info = $this->model_setting_store->getStore($this->request->post['store_id']);
             if ($store_info) {
                 $store_name = $store_info['name'];
             } else {
                 $store_name = $this->config->get('config_name');
             }
             $this->load->model('sale/customer');
             $this->load->model('sale/customer_group');
             $this->load->model('sale/affiliate');
             $this->load->model('sale/order');
             if (isset($this->request->get['page'])) {
                 $page = $this->request->get['page'];
             } else {
                 $page = 1;
             }
             $telephone_total = 0;
             $telephones = array();
             switch ($this->request->post['to']) {
                 case 'newsletter':
                     $customer_data = array('filter_newsletter' => 1, 'start' => ($page - 1) * 10, 'limit' => 10);
                     $telephone_total = $this->model_sale_customer->getTotalCustomers($customer_data);
                     $results = $this->model_sale_customer->getCustomers($customer_data);
                     foreach ($results as $result) {
                         $telephones[] = $result['telephone'];
                     }
                     break;
                 case 'customer_all':
                     $customer_data = array('start' => ($page - 1) * 10, 'limit' => 10);
                     $telephone_total = $this->model_sale_customer->getTotalCustomers($customer_data);
                     $results = $this->model_sale_customer->getCustomers($customer_data);
                     foreach ($results as $result) {
                         $telephones[] = $result['telephone'];
                     }
                     break;
                 case 'customer_group':
                     $customer_data = array('filter_customer_group_id' => $this->request->post['customer_group_id'], 'start' => ($page - 1) * 10, 'limit' => 10);
                     $telephone_total = $this->model_sale_customer->getTotalCustomers($customer_data);
                     $results = $this->model_sale_customer->getCustomers($customer_data);
                     foreach ($results as $result) {
                         $telephones[$result['customer_id']] = $result['telephone'];
                     }
                     break;
                 case 'customer':
                     if (!empty($this->request->post['customer'])) {
                         foreach ($this->request->post['customer'] as $customer_id) {
                             $customer_info = $this->model_sale_customer->getCustomer($customer_id);
                             if ($customer_info) {
                                 $telephones[] = $customer_info['telephone'];
                             }
                         }
                     }
                     break;
                 case 'affiliate_all':
                     $affiliate_data = array('start' => ($page - 1) * 10, 'limit' => 10);
                     $telephone_total = $this->model_sale_affiliate->getTotalAffiliates($affiliate_data);
                     $results = $this->model_sale_affiliate->getAffiliates($affiliate_data);
                     foreach ($results as $result) {
                         $telephones[] = $result['telephone'];
                     }
                     break;
                 case 'affiliate':
                     if (!empty($this->request->post['affiliate'])) {
                         foreach ($this->request->post['affiliate'] as $affiliate_id) {
                             $affiliate_info = $this->model_sale_affiliate->getAffiliate($affiliate_id);
                             if ($affiliate_info) {
                                 $telephones[] = $affiliate_info['telephone'];
                             }
                         }
                     }
                     break;
                 case 'product':
                     if (isset($this->request->post['product'])) {
                         $telephone_total = $this->model_sale_order->getTotalEmailsByProductsOrdered($this->request->post['product']);
                         $results = $this->model_sale_order->getEmailsByProductsOrdered($this->request->post['product'], ($page - 1) * 10, 10);
                         foreach ($results as $result) {
                             $telephones[] = $result['telephone'];
                         }
                     }
                     break;
             }
             $telephones = array_unique($telephones);
             if ($telephones) {
                 $start = ($page - 1) * 10;
                 $end = $start + 10;
                 if ($end < $telephone_total) {
                     $json['success'] = sprintf($this->language->get('text_sent'), $start, $telephone_total);
                 } else {
                     $json['success'] = $this->language->get('text_success');
                 }
                 if ($end < $telephone_total) {
                     $json['next'] = str_replace('&amp;', '&', $this->url->link('module/rajasmsmassindo/send', 'token=' . $this->session->data['token'] . '&page=' . ($page + 1)));
                 } else {
                     $json['next'] = '';
                 }
                 $message = $store_name . ' ' . html_entity_decode($this->request->post['message'], ENT_QUOTES, 'UTF-8');
                 foreach ($telephones as $nohp) {
                     $sms = new sms();
                     $sms->key = $this->config->get('rajasmsindo_key');
                     $sms->phone = $this->config->get('rajasmsindo_smsphone');
                     $sms->username = $this->config->get('rajasmsindo_user');
                     $sms->password = $this->config->get('rajasmsindo_password');
                     $sms->smsmode = $this->config->get('rajasmsindo_smsmode');
                     $sms->modem = $this->config->get('rajasmsindo_modem');
                     $sms->setTo($nohp);
                     $sms->setText($message);
                     $sms->send();
                 }
             }
         }
     }
     $this->response->setOutput(json_encode($json));
 }