Advertisement
Guest User

Untitled

a guest
Dec 16th, 2009
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.92 KB | None | 0 0
  1.     public function confirm($order_id, $order_status_id, $comment = '') {
  2.         $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'");
  3.          
  4.         if ($order_query->num_rows) {  
  5.             $language = new Language($order_query->row['language']);
  6.             $language->load('checkout/confirm');
  7.            
  8.             $this->load->model('localisation/currency');
  9.            
  10.             $subject = sprintf($language->get('mail_new_order_subject'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'), $order_id);
  11.             $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'] . "'");
  12.             $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
  13.             $order_total_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' ORDER BY sort_order ASC");
  14.             $order_download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "'");
  15.            
  16.             foreach ($order_product_query->rows as $product) {
  17.                 $option_data = array();
  18.                
  19.                 $options = $this->getOrderOptions($order_id, $product['order_product_id']);
  20.    
  21.                 foreach ($options as $option) {
  22.                     $option_data[] = array(
  23.                         'name'  => $option['name'],
  24.                         'value' => $option['value']
  25.                     );
  26.                 }
  27.              
  28.                 $orderProducts[] = array(
  29.                     'name'     => $product['name'],
  30.                     'model'    => $product['model'],
  31.                     'option'   => $option_data,
  32.                     'quantity' => $product['quantity'],
  33.                     'price'    => $this->currency->format($product['price'], $order_query->row['currency'], $order_query->row['value']),
  34.                     'total'    => $this->currency->format($product['total'], $order_query->row['currency'], $order_query->row['value'])
  35.                 );
  36.             }
  37.            
  38.     /**
  39.      * HTML Order Email
  40.      * @ Lee Turver
  41.      */
  42.    
  43.     $htmlMessage = '<html>
  44.                 <head>
  45.                 <title>' . $this->config->get('config_store') . ' - Order Confirmation</title>
  46.                 </head>
  47.                 <body>
  48.                     <table cellspacing="0" cellpadding="0" border="0" width="98%" style="margin-top:10px; font-family: Arial, Verdana, Helvetica, sans-serif; margin-bottom:10px;">
  49.                         <tr>
  50.                             <td align="center" valign="top">
  51.                                 <!-- [ header starts here] -->
  52.                                 <table cellspacing="0" cellpadding="0" border="0" width="650">
  53.                                     <tr>
  54.                                         <td valign="top"><img src="http://demo.opencart.com/image/logo.png" alt="' . $this->config->get('config_store') . '" border="0"/></td>
  55.                                     </tr>
  56.                                 </table>
  57.                                 <!-- [ middle starts here] -->
  58.                                 <table cellspacing="0" cellpadding="0" border="0" width="650">
  59.                                     <tr>
  60.                                         <td valign="top">
  61.                                             <p style="font-size: 10pt;">
  62.                                                 <strong>Hello ' . $order_query->row['firstname'] . ' ' . $order_query->row['lastname'] . '</strong>,<br/>
  63.                                                 ' . sprintf($language->get('mail_new_order_greeting'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8')) . '
  64.                                             </p>
  65.                                             <p style="font-size: 10pt;">Your order confirmation is below. Thank you again for your business.</p>
  66.                                            
  67.                                             <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>
  68.                                            
  69.                                             <table cellspacing="0" cellpadding="0" border="0" width="100%">
  70.                                                 <thead>
  71.                                                     <tr>
  72.                                                         <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;">
  73.                                                             Billing Information:
  74.                                                         </th>
  75.                                                         <th width="3%"></th>
  76.                                                         <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;">
  77.                                                             Payment Method:
  78.                                                         </th>
  79.                                                     </tr>
  80.                                                 </thead>
  81.                                                 <tbody>
  82.                                                     <tr>
  83.                                                         <td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">
  84.                                                             ' . $order_query->row['payment_firstname'] . ' ' . $order_query->row['payment_lastname'] . '<br />
  85.                                                             ' . (!empty($order_query->row['payment_company']) ? $order_query->row['payment_company'] . '<br />' : '') . '
  86.                                                             ' . (!empty($order_query->row['payment_address_1']) ? $order_query->row['payment_address_1'] . '<br />' : '') . '
  87.                                                             ' . (!empty($order_query->row['payment_address_2']) ? $order_query->row['payment_address_2'] . '<br />' : '') . '
  88.                                                             ' . (!empty($order_query->row['payment_city']) ? $order_query->row['payment_city'] . '<br />' : '') . '
  89.                                                             ' . (!empty($order_query->row['payment_postcode']) ? $order_query->row['payment_postcode'] . '<br />' : '') . '
  90.                                                             ' . (!empty($order_query->row['payment_zone']) ? $order_query->row['payment_zone'] . '<br />' : '') . '
  91.                                                             ' . (!empty($order_query->row['payment_country']) ? $order_query->row['payment_country'] : '') . '
  92.                                                         </td>
  93.                                                         <td>&nbsp;</td>
  94.                                                         <td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">
  95.                                                             ' . $order_query->row['payment_method'] . '
  96.                                                         </td>
  97.                                                     </tr>
  98.                                                 </tbody>
  99.                                             </table>
  100.                                            
  101.                                             <br/>
  102.                    
  103.                                             <table cellspacing="0" cellpadding="0" border="0" width="100%">
  104.                                             <thead>
  105.                                                 <tr>
  106.                                                     <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;">
  107.                                                         Shipping Information:
  108.                                                     </th>
  109.                                                     <th width="3%"></th>
  110.                                                     <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;">
  111.                                                         Shipping Method:
  112.                                                     </th>
  113.                                                 </tr>
  114.                                             </thead>
  115.                                             <tbody>
  116.                                             <tr>
  117.                                                 <td valign="top" style="font-size: 10pt; padding:7px 9px 9px 9px; border:1px solid #bebcb7; border-top:0; background:#f8f7f5;">                                
  118.                                                     ' . $order_query->row['shipping_firstname'] . ' ' . $order_query->row['shipping_lastname'] . '<br />
  119.                                                     ' . (!empty($order_query->row['shipping_company']) ? $order_query->row['shipping_company'] . '<br />' : '') . '
  120.                                                     ' . (!empty($order_query->row['shipping_address_1']) ? $order_query->row['shipping_address_1'] . '<br />' : '') . '
  121.                                                     ' . (!empty($order_query->row['shipping_address_2']) ? $order_query->row['shipping_address_2'] . '<br />' : '') . '
  122.                                                     ' . (!empty($order_query->row['shipping_city']) ? $order_query->row['shipping_city'] . '<br />' : '') . '
  123.                                                     ' . (!empty($order_query->row['shipping_postcode']) ? $order_query->row['shipping_postcode'] . '<br />' : '') . '
  124.                                                     ' . (!empty($order_query->row['shipping_zone']) ? $order_query->row['shipping_zone'] . '<br />' : '') . '
  125.                                                     ' . (!empty($order_query->row['shipping_country']) ? $order_query->row['shipping_country'] : '') . '
  126.                                                 </td>
  127.                                                 <td>&nbsp;</td>
  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['shipping_method'] . '
  130.                                                 </td>
  131.                                             </tr>
  132.                                         </tbody>
  133.                                         </table>
  134.                                        
  135.                                         <br/>
  136.                    
  137.                                         <table cellspacing="0" cellpadding="0" border="0" width="100%" style="border:1px solid #bebcb7; background:#f8f7f5;">
  138.                                             <thead>
  139.                                                 <tr>
  140.                                                 <th align="left" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Item</th>
  141.                                                 <th align="center" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Qty</th>
  142.                                                 <th align="center" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Unit Price</th>
  143.                                                 <th align="right" bgcolor="#920400" style="color: #ffffff; font-size: 10pt; padding:3px 9px">Subtotal</th>
  144.                                             </tr>
  145.                                         </thead>
  146.  
  147.                                           <tbody bgcolor="#eeeded">';
  148.                                            
  149.                                             foreach($orderProducts as $product):
  150.                                                 $htmlMessage .= '
  151.                                                 <tr>
  152.                                                     <td align="left" valign="top" style="padding:3px 9px; font-size: 10pt; ">
  153.                                                         <strong>' . $product['name'] . '</strong>';
  154.                                                         foreach ($product['option'] as $option):
  155.                                                             $htmlMessage .= '<br />&nbsp;<small> - '. $option['name'] . ' ' . $option['value'] . '</small>';
  156.                                                         endforeach;
  157.                                                     $htmlMessage .= '
  158.                                                     </td>
  159.                                                     <td align="center" valign="top" style="padding:3px 9px; font-size: 10pt;">' . $product['quantity'] . '</td>
  160.                                                     <td align="center" valign="top" style="padding:3px 9px; font-size: 10pt;">' . $product['price'] . '</td>
  161.                                                     <td align="right" valign="top" style="padding:3px 9px; font-size: 10pt; ">' . $product['total'] . '</td>
  162.                                                 </tr>';
  163.                                             endforeach;
  164.                                            
  165.                                         $htmlMessage .= '
  166.                                         </tbody>
  167.                                        
  168.                                         <tfoot>';
  169.  
  170.                                         foreach ($order_total_query->rows as $result):
  171.                                             if($result['title'] != 'Total:'):
  172.                                                 $htmlMessage .= '
  173.                                                     <tr>
  174.                                                         <td colspan="3" align="right" style="padding:3px 9px; font-size: 10pt;">' . $result['title'] . '</td>
  175.                                                         <td align="right" style="padding:3px 9px; font-size: 10pt;"><span class="price">' . $result['text'] . '</span></td>
  176.                                                     </tr>';
  177.                                             else:
  178.                                                 $htmlMessage .= '
  179.                                                     <tr bgcolor="#DEE5E8">
  180.                                                         <td colspan="3" align="right" style="padding:3px 9px; font-size: 10pt;"><strong><big>' . $result['title'] . '</big></strong></td>
  181.                                                         <td align="right" style="padding:6px 9px; font-size: 10pt;"><strong><big><span class="price">' . $result['text'] . '</span></big></strong></td>
  182.                                                     </tr>';                                        
  183.                                             endif;
  184.                                         endforeach;
  185.                                        
  186.                                         $htmlMessage .= '
  187.                                         </tfoot>
  188.                                     </table>
  189.  
  190.                                     <br/>
  191.                    
  192.                                     <p>Thank you again,<br/><strong>' . $this->config->get('config_store') . '</strong></p>
  193.                                 </td>
  194.                             </tr>
  195.                         </table>
  196.                     </td>
  197.                 </tr>
  198.             </table>
  199.         </body>
  200.         </html>';          
  201.    
  202.     /**
  203.      * HTML Order Text End
  204.      * Begin Plain Text Message
  205.      */
  206.             // Text Mail
  207.             $message = sprintf($language->get('mail_new_order_greeting'), html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8')) . "\n\n";
  208.             $message .= $language->get('mail_new_order_order') . ' ' . $order_id . "\n";
  209.             $message .= $language->get('mail_new_order_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . "\n";
  210.             $message .= $language->get('mail_new_order_order_status') . ' ' . $order_status_query->row['name'] . "\n\n";
  211.             $message .= $language->get('mail_new_order_product') . "\n";
  212.            
  213.             foreach ($order_product_query->rows as $result) {
  214.                 $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";
  215.             }
  216.            
  217.             $message .= "\n";
  218.            
  219.             $message .= $language->get('mail_new_order_total') . "\n";
  220.            
  221.             foreach ($order_total_query->rows as $result) {
  222.                 $message .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
  223.             }          
  224.            
  225.             $message .= "\n";
  226.            
  227.             $message .= $language->get('mail_new_order_invoice') . "\n";
  228.             $message .= html_entity_decode($this->url->http('account/invoice&order_id=' . $order_id), ENT_QUOTES, 'UTF-8') . "\n\n";
  229.            
  230.             if ($order_download_query->num_rows) {
  231.                 $message .= $language->get('mail_new_order_download') . "\n";
  232.                 $message .= $this->url->http('account/download') . "\n\n";
  233.             }
  234.            
  235.             if ($comment) {
  236.                 $message .= $language->get('mail_new_order_comment') . "\n\n";
  237.                 $message .= $comment . "\n\n";
  238.             }
  239.            
  240.             $message .= $language->get('mail_new_order_footer');
  241.        
  242.             $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'));
  243.             $mail->setTo($order_query->row['email']);
  244.             $mail->setFrom($this->config->get('config_email'));
  245.             $mail->setSender(html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'));
  246.             $mail->setSubject($subject);
  247.             $mail->setHtml($htmlMessage);
  248.             $mail->setText($message);
  249.             $mail->send();
  250.            
  251.             if ($this->config->get('config_alert_mail')) {
  252.                 $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'));
  253.                 $mail->setTo($this->config->get('config_email'));
  254.                 $mail->setFrom($this->config->get('config_email'));
  255.                 $mail->setSender(html_entity_decode($this->config->get('config_store'), ENT_QUOTES, 'UTF-8'));
  256.                 $mail->setSubject($subject);
  257.                 $mail->setHtml($htmlMessage);
  258.                 $mail->setText($message);
  259.                 $mail->send();
  260.             }
  261.            
  262.             if ($this->config->get('config_stock_subtract')) {
  263.                 $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
  264.            
  265.                 foreach ($order_product_query->rows as $product) {
  266.                     $this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "'");
  267.                
  268.                     $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'] . "'");
  269.                
  270.                     foreach ($order_option_query->rows as $option) {
  271.                         $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'");
  272.                     }
  273.                 }
  274.             }      
  275.         }
  276.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement