Advertisement
Guest User

Untitled

a guest
Dec 17th, 2009
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 28.06 KB | None | 0 0
  1. <?php
  2. class ModelCheckoutOrder extends Model {
  3.     public function getOrder($order_id) {
  4.         $query = $this->db->query("SELECT *, c1.iso_code_2 AS shipping_iso_code_2, c1.iso_code_3 AS shipping_iso_code_3, c2.iso_code_2 AS payment_iso_code_2, c2.iso_code_3 AS shipping_iso_code_3, z1.code AS shipping_zone_code, z2.code AS payment_zone_code FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "country c1 ON (o.shipping_country_id = c1.country_id) LEFT JOIN " . DB_PREFIX . "country c2 ON (o.payment_country_id = c2.country_id) LEFT JOIN " . DB_PREFIX . "zone z1 ON (o.payment_zone_id = z1.zone_id) LEFT JOIN " . DB_PREFIX . "zone z2 ON (o.payment_zone_id = z2.zone_id) WHERE o.order_id = '" . (int)$order_id . "'");
  5.    
  6.         return $query->row;
  7.     }  
  8.    
  9.     public function create($data) {
  10.         $query = $this->db->query("SELECT order_id FROM `" . DB_PREFIX . "order` WHERE date_added < '" . date('Y-m-d', strtotime('-1 month')) . "' AND order_status_id = '0'");
  11.        
  12.         foreach ($query->rows as $result) {
  13.             $this->db->query("DELETE FROM `" . DB_PREFIX . "order` WHERE order_id = '" . (int)$result['order_id'] . "'");
  14.             $this->db->query("DELETE FROM " . DB_PREFIX . "order_history WHERE order_id = '" . (int)$result['order_id'] . "'");
  15.             $this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$result['order_id'] . "'");
  16.             $this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$result['order_id'] . "'");
  17.             $this->db->query("DELETE FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$result['order_id'] . "'");
  18.             $this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$result['order_id'] . "'");
  19.         }      
  20.        
  21.         $this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET customer_id = '" . (int)$data['customer_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', total = '" . (float)$data['total'] . "', language_id = '" . (int)$data['language_id'] . "', currency = '" . $this->db->escape($data['currency']) . "', currency_id = '" . (int)$data['currency_id'] . "', value = '" . (float)$data['value'] . "', coupon_id = '" . (int)$data['coupon_id'] . "', ip = '" . $this->db->escape($data['ip']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', comment = '" . $this->db->escape($data['comment']) . "', date_modified = NOW(), date_added = NOW()");
  22.  
  23.         $order_id = $this->db->getLastId();
  24.  
  25.         foreach ($data['products'] as $product) {
  26.             $this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', tax = '" . (float)$product['tax'] . "', quantity = '" . (int)$product['quantity'] . "'");
  27.  
  28.             $order_product_id = $this->db->getLastId();
  29.  
  30.             foreach ($product['option'] as $option) {
  31.                 $this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_value_id = '" . (int)$option['product_option_value_id'] . "', name = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', price = '" . (float)$product['price'] . "', prefix = '" . $this->db->escape($option['prefix']) . "'");
  32.             }
  33.                
  34.             foreach ($product['download'] as $download) {
  35.                 $this->db->query("INSERT INTO " . DB_PREFIX . "order_download SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', name = '" . $this->db->escape($download['name']) . "', filename = '" . $this->db->escape($download['filename']) . "', mask = '" . $this->db->escape($download['mask']) . "', remaining = '" . (int)($download['remaining'] * $product['quantity']) . "'");
  36.             }  
  37.         }
  38.        
  39.         foreach ($data['totals'] as $total) {
  40.             $this->db->query("INSERT INTO " . DB_PREFIX . "order_total SET order_id = '" . (int)$order_id . "', title = '" . $this->db->escape($total['title']) . "', text = '" . $this->db->escape($total['text']) . "', `value` = '" . (float)$total['value'] . "', sort_order = '" . (int)$total['sort_order'] . "'");
  41.         }  
  42.  
  43.         return $order_id;
  44.     }
  45.  
  46.        public function confirm($order_id, $order_status_id, $comment = '') {
  47.       $order_query = $this->db->query("SELECT *, l.code AS language FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "language l ON (o.language_id = l.language_id) WHERE o.order_id = '" . (int)$order_id . "' AND o.order_status_id = '0'");
  48.        
  49.       if ($order_query->num_rows) {  
  50.          $language = new Language($order_query->row['language']);
  51.          $language->load('checkout/confirm');
  52.          
  53.          $this->load->model('localisation/currency');
  54.          
  55.          $subject = sprintf($language->get('mail_new_order_subject'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'), $order_id);
  56.          $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int)$order_status_id . "' AND language_id = '" . (int)$order_query->row['language_id'] . "'");
  57.          $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
  58.          $order_total_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' ORDER BY sort_order ASC");
  59.          $order_download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "'");
  60.          
  61.          foreach ($order_product_query->rows as $product) {
  62.             $option_data = array();
  63.            
  64.             $options = $this->getOrderOptions($order_id, $product['order_product_id']);
  65.    
  66.             foreach ($options as $option) {
  67.                $option_data[] = array(
  68.                   'name'  => $option['name'],
  69.                   'value' => $option['value']
  70.                );
  71.             }
  72.            
  73.             $orderProducts[] = array(
  74.                'name'     => $product['name'],
  75.                'model'    => $product['model'],
  76.                'option'   => $option_data,
  77.                'quantity' => $product['quantity'],
  78.                'price'    => $this->currency->format($product['price'], $order_query->row['currency'], $order_query->row['value']),
  79.                'total'    => $this->currency->format($product['total'], $order_query->row['currency'], $order_query->row['value'])
  80.             );
  81.          }
  82.          
  83.    /**
  84.     * HTML Order Email
  85.     * @ Lee Turver
  86.     */
  87.    
  88.    $htmlMessage = '<html>
  89.            <head>
  90.            <title>' . $this->config->get('config_store') . ' - Order Confirmation</title>
  91.            </head>
  92.            <body>
  93.               <table cellspacing="0" cellpadding="0" border="0" width="98%" style="margin-top:10px; font-family: Arial, Verdana, Helvetica, sans-serif; margin-bottom:10px;">
  94.                  <tr>
  95.                     <td align="center" valign="top">
  96.                        <!-- [ header starts here] -->
  97.                        <table cellspacing="0" cellpadding="0" border="0" width="650">
  98.                           <tr>
  99.                              <td valign="top"><img src="http://shop.disifin.co.uk/image/logo.png" alt="' . $this->config->get('config_store') . '" border="0"/></td>
  100.                           </tr>
  101.                        </table>
  102.                        <!-- [ middle starts here] -->
  103.                        <table cellspacing="0" cellpadding="0" border="0" width="650">
  104.                           <tr>
  105.                              <td valign="top">
  106.                                 <p style="font-size: 10pt;">
  107.                                    <strong>Hello ' . $order_query->row['firstname'] . ' ' . $order_query->row['lastname'] . '</strong>,<br/>
  108.                                    ' . sprintf($language->get('mail_new_order_greeting'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8')) . '
  109.                                 </p>
  110.                                 <p style="font-size: 10pt;">Your order confirmation is below. Thank you again for your business.</p>
  111.                                
  112.                                 <h3 style="border-bottom:2px solid #eee; font-size:1.05em; padding-bottom:1px; ">Your Order #'. $order_id . '<small> (placed on ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . ')</small></h3>
  113.                                
  114.                                 <table cellspacing="0" cellpadding="0" border="0" width="100%">
  115.                                    <thead>
  116.                                       <tr>
  117.                                          <th align="left" width="48.5%" bgcolor="#920400" style="font-size: 10pt; padding:5px 9px 6px 9px; color: #fff; border:1px solid #bebcb7; border-bottom:none; line-height:1em;">
  118.                                             Billing Information:
  119.                                          </th>
  120.                                          <th width="3%"></th>
  121.                                          <th align="left" width="48.5%" bgcolor="#920400" style="font-size: 10pt; padding:5px 9px 6px 9px; color: #ffffff; border:1px solid #bebcb7; border-bottom:none; line-height:1em;">
  122.                                             Payment Method:
  123.                                          </th>
  124.                                       </tr>
  125.                                    </thead>
  126.                                    <tbody>
  127.                                       <tr>
  128.                                          <td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">
  129.                                             ' . $order_query->row['payment_firstname'] . ' ' . $order_query->row['payment_lastname'] . '<br />
  130.                                             ' . (!empty($order_query->row['payment_company']) ? $order_query->row['payment_company'] . '<br />' : '') . '
  131.                                             ' . (!empty($order_query->row['payment_address_1']) ? $order_query->row['payment_address_1'] . '<br />' : '') . '
  132.                                             ' . (!empty($order_query->row['payment_address_2']) ? $order_query->row['payment_address_2'] . '<br />' : '') . '
  133.                                             ' . (!empty($order_query->row['payment_city']) ? $order_query->row['payment_city'] . '<br />' : '') . '
  134.                                             ' . (!empty($order_query->row['payment_postcode']) ? $order_query->row['payment_postcode'] . '<br />' : '') . '
  135.                                             ' . (!empty($order_query->row['payment_zone']) ? $order_query->row['payment_zone'] . '<br />' : '') . '
  136.                                             ' . (!empty($order_query->row['payment_country']) ? $order_query->row['payment_country'] : '') . '
  137.                                          </td>
  138.                                          <td>&nbsp;</td>
  139.                                          <td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">
  140.                                             ' . $order_query->row['payment_method'] . '
  141.                                          </td>
  142.                                       </tr>
  143.                                    </tbody>
  144.                                 </table>
  145.                                
  146.                                 <br/>
  147.                    
  148.                                 <table cellspacing="0" cellpadding="0" border="0" width="100%">
  149.                                 <thead>
  150.                                    <tr>
  151.                                       <th align="left" width="48.5%" bgcolor="#920400" style="font-size: 10pt; padding:5px 9px 6px 9px; color: #ffffff; border:1px solid #bebcb7; border-bottom:none; line-height:1em;">
  152.                                          Shipping Information:
  153.                                       </th>
  154.                                       <th width="3%"></th>
  155.                                       <th align="left" width="48.5%" bgcolor="#920400" style="font-size: 10pt; padding:5px 9px 6px 9px; color: #ffffff; border:1px solid #bebcb7; border-bottom:none; line-height:1em;">
  156.                                          Shipping Method:
  157.                                       </th>
  158.                                    </tr>
  159.                                 </thead>
  160.                                 <tbody>
  161.                                 <tr>
  162.                                    <td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">                                
  163.                                       ' . $order_query->row['shipping_firstname'] . ' ' . $order_query->row['shipping_lastname'] . '<br />
  164.                                       ' . (!empty($order_query->row['shipping_company']) ? $order_query->row['shipping_company'] . '<br />' : '') . '
  165.                                       ' . (!empty($order_query->row['shipping_address_1']) ? $order_query->row['shipping_address_1'] . '<br />' : '') . '
  166.                                       ' . (!empty($order_query->row['shipping_address_2']) ? $order_query->row['shipping_address_2'] . '<br />' : '') . '
  167.                                       ' . (!empty($order_query->row['shipping_city']) ? $order_query->row['shipping_city'] . '<br />' : '') . '
  168.                                       ' . (!empty($order_query->row['shipping_postcode']) ? $order_query->row['shipping_postcode'] . '<br />' : '') . '
  169.                                       ' . (!empty($order_query->row['shipping_zone']) ? $order_query->row['shipping_zone'] . '<br />' : '') . '
  170.                                       ' . (!empty($order_query->row['shipping_country']) ? $order_query->row['shipping_country'] : '') . '
  171.                                    </td>
  172.                                    <td>&nbsp;</td>
  173.                                    <td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">
  174.                                       ' . $order_query->row['shipping_method'] . '
  175.                                    </td>
  176.                                 </tr>
  177.                              </tbody>
  178.                              </table>
  179.                              
  180.                              <br/>
  181.                    
  182.                              <table cellspacing="0" cellpadding="0" border="0" width="100%" style="border:1px solid #bebcb7; background:#f8f7f5;">
  183.                                 <thead>
  184.                                    <tr>
  185.                                    <th align="left" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Item</th>
  186.                                    <th align="center" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Qty</th>
  187.                                    <th align="center" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Unit Price</th>
  188.                                    <th align="right" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Subtotal</th>
  189.                                 </tr>
  190.                              </thead>
  191.  
  192.                                <tbody bgcolor="#eeeded">';
  193.                                  
  194.                                  foreach($orderProducts as $product):
  195.                                     $htmlMessage .= '
  196.                                    <tr>
  197.                                       <td align="left" valign="top" style="padding:3px 9px; font-size: 10pt; ">
  198.                                          <strong>' . $product['name'] . '</strong>';
  199.                                           foreach ($product['option'] as $option):
  200.                                              $htmlMessage .= '<br />&nbsp;<small> - '. $option['name'] . ' ' . $option['value'] . '</small>';
  201.                                           endforeach;
  202.                                        $htmlMessage .= '
  203.                                       </td>
  204.                                       <td align="center" valign="top" style="padding:3px 9px; font-size: 10pt;">' . $product['quantity'] . '</td>
  205.                                       <td align="center" valign="top" style="padding:3px 9px; font-size: 10pt;">' . $product['price'] . '</td>
  206.                                       <td align="right" valign="top" style="padding:3px 9px; font-size: 10pt; ">' . $product['total'] . '</td>
  207.                                    </tr>';
  208.                                  endforeach;
  209.                                  
  210.                               $htmlMessage .= '
  211.                              </tbody>
  212.                              
  213.                              <tfoot>';
  214.  
  215.                               foreach ($order_total_query->rows as $result):
  216.                                  if($result['title'] != 'Total:'):
  217.                                     $htmlMessage .= '
  218.                                       <tr>
  219.                                          <td colspan="3" align="right" style="padding:3px 9px; font-size: 10pt;">' . $result['title'] . '</td>
  220.                                          <td align="right" style="padding:3px 9px; font-size: 10pt;"><span class="price">' . $result['text'] . '</span></td>
  221.                                       </tr>';
  222.                                  else:
  223.                                     $htmlMessage .= '
  224.                                       <tr bgcolor="#DEE5E8">
  225.                                          <td colspan="3" align="right" style="padding:3px 9px; font-size: 10pt;"><strong><big>' . $result['title'] . '</big></strong></td>
  226.                                          <td align="right" style="padding:6px 9px; font-size: 10pt;"><strong><big><span class="price">' . $result['text'] . '</span></big></strong></td>
  227.                                       </tr>';                                
  228.                                  endif;
  229.                               endforeach;
  230.                              
  231.                               $htmlMessage .= '
  232.                              </tfoot>
  233.                           </table>
  234.  
  235.                           <br/>
  236.                    
  237.                           <p>Thank you again,<br/><strong>' . $this->config->get('config_store') . '</strong></p>
  238.                        </td>
  239.                     </tr>
  240.                  </table>
  241.               </td>
  242.            </tr>
  243.         </table>
  244.      </body>
  245.      </html>';        
  246.    
  247.    /**
  248.     * HTML Order Text End
  249.     * Begin Plain Text Message
  250.     */
  251.          // Text Mail
  252.          $message = sprintf($language->get('mail_new_order_greeting'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8')) . "\n\n";
  253.          $message .= $language->get('mail_new_order_order') . ' ' . $order_id . "\n";
  254.          $message .= $language->get('mail_new_order_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . "\n";
  255.          $message .= $language->get('mail_new_order_order_status') . ' ' . $order_status_query->row['name'] . "\n\n";
  256.          $message .= $language->get('mail_new_order_product') . "\n";
  257.          
  258.          foreach ($order_product_query->rows as $result) {
  259.             $message .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_query->row['currency'], $order_query->row['value']), ENT_NOQUOTES, 'UTF-8') . "\n";
  260.          }
  261.          
  262.          $message .= "\n";
  263.          
  264.          $message .= $language->get('mail_new_order_total') . "\n";
  265.          
  266.          foreach ($order_total_query->rows as $result) {
  267.             $message .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
  268.          }        
  269.          
  270.          $message .= "\n";
  271.          
  272.          $message .= $language->get('mail_new_order_invoice') . "\n";
  273.          $message .= html_entity_decode($this->url->http('account/invoice&order_id=' . $order_id), ENT_QUOTES, 'UTF-8') . "\n\n";
  274.          
  275.          if ($order_download_query->num_rows) {
  276.             $message .= $language->get('mail_new_order_download') . "\n";
  277.             $message .= $this->url->http('account/download') . "\n\n";
  278.          }
  279.          
  280.          if ($comment) {
  281.             $message .= $language->get('mail_new_order_comment') . "\n\n";
  282.             $message .= $comment . "\n\n";
  283.          }
  284.          
  285.          $message .= $language->get('mail_new_order_footer');
  286.      
  287.          $mail = new Mail($this->config->get('config_mail_protocol'), $this->config->get('config_smtp_host'), $this->config->get('config_smtp_username'), html_entity_decode($this->config->get('config_smtp_password'), ENT_QUOTES, 'UTF-8'), $this->config->get('config_smtp_port'), $this->config->get('config_smtp_timeout'));
  288.          $mail->setTo($order_query->row['email']);
  289.          $mail->setFrom($this->config->get('config_email'));
  290.          $mail->setSender(html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'));
  291.          $mail->setSubject($subject);
  292.          $mail->setHtml($htmlMessage);
  293.          $mail->setText($message);
  294.          $mail->send();
  295.          
  296.          if ($this->config->get('config_alert_mail')) {
  297.             $mail = new Mail($this->config->get('config_mail_protocol'), $this->config->get('config_smtp_host'), $this->config->get('config_smtp_username'), $this->config->get('config_smtp_password'), $this->config->get('config_smtp_port'), $this->config->get('config_smtp_timeout'));
  298.             $mail->setTo($this->config->get('config_email'));
  299.             $mail->setFrom($this->config->get('config_email'));
  300.             $mail->setSender(html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'));
  301.             $mail->setSubject($subject);
  302.             $mail->setHtml($htmlMessage);
  303.             $mail->setText($message);
  304.             $mail->send();
  305.          }
  306.          
  307.          if ($this->config->get('config_stock_subtract')) {
  308.             $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
  309.          
  310.             foreach ($order_product_query->rows as $product) {
  311.                $this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "'");
  312.            
  313.                $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$product['order_product_id'] . "'");
  314.            
  315.                foreach ($order_option_query->rows as $option) {
  316.                   $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
  317.                }
  318.             }
  319.          }      
  320.       }
  321.    }
  322.    
  323.     public function update($order_id, $order_status_id, $comment = '', $notifiy = FALSE) {
  324.         $order_query = $this->db->query("SELECT *, o.language_id, l.code AS language FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "language l ON (o.language_id = l.language_id) WHERE o.order_id = '" . (int)$order_id . "' AND o.order_status_id > '0'");
  325.        
  326.         if ($order_query->num_rows) {
  327.             $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '" . (int)$order_status_id . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");
  328.        
  329.             $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (int)$notifiy . "', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");
  330.    
  331.             if ($notifiy) {
  332.                 $language = new Language($order_query->row['language']);
  333.                 $language->load('checkout/confirm');
  334.    
  335.                 $subject = sprintf($language->get('mail_update_order_subject'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'), $order_id);
  336.    
  337.                 $message  = $language->get('mail_update_order_order') . ' ' . $order_id . "\n";
  338.                 $message .= $language->get('mail_update_order_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . "\n\n";
  339.                 $message .= $language->get('mail_update_order_order_status') . "\n\n";
  340.                
  341.                 $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int)$order_status_id . "' AND language_id = '" . (int)$order_query->row['language_id'] . "'");
  342.                
  343.                 $message .= $order_status_query->row['name'] . "\n\n";
  344.                    
  345.                 $message .= $language->get('mail_update_order_invoice') . "\n";
  346.                 $message .= html_entity_decode($this->url->http('account/invoice&order_id=' . $order_id), ENT_QUOTES, 'UTF-8') . "\n\n";
  347.                    
  348.                 if ($comment) {
  349.                     $message .= $language->get('mail_update_order_comment') . "\n\n";
  350.                     $message .= $comment . "\n\n";
  351.                 }
  352.                    
  353.                 $message .= $language->get('mail_update_order_footer');
  354.  
  355.                 $mail = new Mail($this->config->get('config_mail_protocol'), $this->config->get('config_smtp_host'), $this->config->get('config_smtp_username'), html_entity_decode($this->config->get('config_smtp_password'), ENT_QUOTES, 'UTF-8'), $this->config->get('config_smtp_port'), $this->config->get('config_smtp_timeout'));
  356.                 $mail->setTo($order_query->row['email']);
  357.                 $mail->setFrom($this->config->get('config_email'));
  358.                 $mail->setSender(html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'));
  359.                 $mail->setSubject($subject);
  360.                 $mail->setText($message);
  361.                 $mail->send();
  362.             }
  363.         }
  364.     }
  365. }
  366. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement