2016-11-11 1 views
1

Ich muss eine Excel-Datei erstellen und senden Sie es per E-Mail an den Ladenbesitzer auf neue Bestellungen.Opencart senden benutzerdefinierte E-Mail auf neue Bestellung

Ich habe diesen Code in public_html/catalog/Modell/Kasse eingefügt/order.php

//emails have been changed on purpose 

      $email_to = "my email"; 
    $mail2 = new Mail(); 

    $mail2->protocol = $this->config->get('config_mail_protocol'); 
    $mail2->parameter = $this->config->get('config_mail_parameter'); 
    $mail2->hostname = $this->config->get('config_smtp_host'); 
    $mail2->username = $this->config->get('config_smtp_username'); 
    $mail2->password = $this->config->get('config_smtp_password'); 
    $mail2->port = $this->config->get('config_smtp_port'); 
    $mail2->timeout = $this->config->get('config_smtp_timeout');    
    $mail2->setTo($email_to); 
    $mail2->setFrom("[email protected]"); 
    $mail2->setSender("[email protected]"); 
    $mail2->setSubject("test send mail"); 
    $mail2->setText("test message body text"); 

    $mail2->send(); 

ich den Code oben rechts nach diesem eingefügt haben:

// Admin Alert Mail 

    if ($this->config->get('config_order_mail')) { 
        $subject = sprintf($language->get('text_new_subject'), html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8'), $order_id); 

        // HTML Mail 
        $data['text_greeting'] = $language->get('text_new_received'); 

        if ($comment) { 
         if ($order_info['comment']) { 
          $data['comment'] = nl2br($comment) . '<br/><br/>' . $order_info['comment']; 
         } else { 
          $data['comment'] = nl2br($comment); 
         } 
        } else { 
         if ($order_info['comment']) { 
          $data['comment'] = $order_info['comment']; 
         } else { 
          $data['comment'] = ''; 
         } 
        } 

        $data['text_download'] = ''; 

        $data['text_footer'] = ''; 

        $data['text_link'] = ''; 
        $data['link'] = ''; 
        $data['download'] = ''; 

        // Text 
        $text = $language->get('text_new_received') . "\n\n"; 
        $text .= $language->get('text_new_order_id') . ' ' . $order_id . "\n"; 
        $text .= $language->get('text_new_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_info['date_added'])) . "\n"; 
        $text .= $language->get('text_new_order_status') . ' ' . $order_status . "\n\n"; 
        $text .= $language->get('text_new_products') . "\n"; 



        foreach ($order_product_query->rows as $product) { 
         $text .= $product['quantity'] . 'x ' . $product['name'] . ' (' . $product['model'] . ') ' . html_entity_decode($this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n"; 

         $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . $product['order_product_id'] . "'"); 

         foreach ($order_option_query->rows as $option) { 
          if ($option['type'] != 'file') { 
           $value = $option['value']; 
          } else { 
           $value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.')); 
          } 

          $text .= chr(9) . '-' . $option['name'] . ' ' . (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value) . "\n"; 
         } 
        } 

        foreach ($order_voucher_query->rows as $voucher) { 
         $text .= '1x ' . $voucher['description'] . ' ' . $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']); 
        } 

        $text .= "\n"; 

        $text .= $language->get('text_new_order_total') . "\n"; 

        foreach ($order_total_query->rows as $total) { 
         $text .= $total['title'] . ': ' . html_entity_decode($this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']), ENT_NOQUOTES, 'UTF-8') . "\n"; 
        } 

        $text .= "\n"; 

        if ($order_info['comment']) { 
         $text .= $language->get('text_new_comment') . "\n\n"; 
         $text .= $order_info['comment'] . "\n\n"; 
        } 

        $mail = new Mail(); 
        $mail->protocol = $this->config->get('config_mail_protocol'); 
        $mail->parameter = $this->config->get('config_mail_parameter'); 
        $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); 
        $mail->smtp_username = $this->config->get('config_mail_smtp_username'); 
        $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); 
        $mail->smtp_port = $this->config->get('config_mail_smtp_port'); 
        $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); 

        $mail->setTo($this->config->get('config_email')); 
        $mail->setFrom($this->config->get('config_email')); 
        $mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')); 
        $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8')); 
        $mail->setHtml($this->load->view('mail/order', $data)); 
        $mail->setText($text); 
        $mail->send(); 

Ich habe auch ein Skript das generiert Excel-Datei, aber ich habe keine Ahnung, wie Sie beide zusammen kombinieren. Jetzt

Probleme:

  1. Customized E-Mail wird nicht auf neuen Auftrag zu senden, aber allgemeine E-Mail über neue Ordnung ohne Probleme erreicht.
  2. Bitte geben Sie alle Ideen, wie in Excel den Code auf einem OpenCart CMS zu generieren.

Antwort

1

Ok, das war viel einfacher als ich erwartet hatte. Da niemand aufgepasst hat, habe ich ein paar Stunden damit verbracht zu recherchieren und eine Lösung gefunden. Also, wenn jemand braucht eine Excel-Datei zu erzeugen, der Lieferfirma geschickt werden müssen, hier ist sie:

offen, ob public_html/System/Speicher/Änderung/Katalog/Modell/Kasse/order.php

oder public_html/catalog/model/checkout/order.php Ursache für manche Leute funktioniert der 2. Link aber für mich funktionierte der 1. Link.

Suche nach dieser:

// Admin Alert Mail 

dann bis diese nach unten scrollen:

$mail = new Mail(); 
       $mail->protocol = $this->config->get('config_mail_protocol'); 
       $mail->parameter = $this->config->get('config_mail_parameter'); 
       $mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname'); 
       $mail->smtp_username = $this->config->get('config_mail_smtp_username'); 
       $mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'); 
       $mail->smtp_port = $this->config->get('config_mail_smtp_port'); 
       $mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout'); 

       $mail->setTo($this->config->get('config_email')); 
       $mail->setFrom($this->config->get('config_email')); 
       $mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')); 
       $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8')); 
       $mail->setHtml($this->load->view('mail/order', $data)); 
       $mail->setText($text); 
       $mail->send(); 

diesen Code Fügen Sie die Excel-Datei zu generieren:

//excel 

         $data2 = array(
     array("ORDER ID" => $order_id, "COMPANY NAME" => "Your company name", "ADDRESS LINE1" =>$data['shipping_address'], "ADDRESS LINE2" => $data['shipping_address_2'],"CONTACT PERSON"=>$order_info['shipping_firstname']." ".$order_info['shipping_lastname'],"CITY" =>$order_info['shipping_city'], "PHONE_1"=>$data['telephone'],"CONTENT" =>"", "WH NUMBER" =>$product['model'],"PIECES"=>$product['quantity'],"COD"=>"","Total"=>$order_info['total']), 
     ); 

    function filterData(&$str) 
    { 
     $str = preg_replace("/\t/", "\\t", $str); 
     $str = preg_replace("/\r?\n/", "\\n", $str); 
     if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; 
    } 

    // file name for download 
    $fileName = $order_id.".xls"; 



    $flag = false; 
    foreach($data2 as $row) { 
     if(!$flag) { 
      // display column names as first row 
     echo implode("\t", array_keys($row)) . "\n"; 
      $flag = true; 
     } 
     // filter data 
    array_walk($row, 'filterData'); 
      $rows= implode("\t", array_keys($row)) . "\n" . implode("\t", array_values($row)) . "\n"; 


     file_put_contents($fileName, $rows); 
    } 

$mail->setTo('email of delivery company or any you need'); 
       $mail->setFrom($this->config->get('config_email')); 
       $mail->setSender(html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8')); 
       $mail->setSubject(html_entity_decode($subject, ENT_QUOTES, 'UTF-8')); 
       $mail->setHtml($this->load->view('mail/excel', $data)); 
       $mail->setText($text); 
       $mail->send(); 

Go/Katalog public_html/view/theme/default/template/mail/und erstelle eine Datei excel.tpl.

Paste dies excel.tpl:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title><?php echo $title; ?></title> 
</head> 
<body style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #000000;"> 
<div style="width: 680px;"><a href="<?php echo $store_url; ?>" title="<?php echo $store_name; ?>"><img src="<?php echo $logo; ?>" alt="<?php echo $store_name; ?>" style="margin-bottom: 20px; border: none;" /></a> 



Find and order in excel file here: 

<a href="http://yourwebsiteurl.com/<?php echo $order_id; ?>.xls">Download</a> 

    <?php if ($customer_id) { ?> 
    <p style="margin-top: 0px; margin-bottom: 20px;"><?php echo $text_link; ?></p> 
    <p style="margin-top: 0px; margin-bottom: 20px;"><a href="<?php echo $link; ?>"><?php echo $link; ?></a></p> 
    <?php } ?> 
    <?php if ($download) { ?> 
    <p style="margin-top: 0px; margin-bottom: 20px;"><?php echo $text_download; ?></p> 
    <p style="margin-top: 0px; margin-bottom: 20px;"><a href="<?php echo $download; ?>"><?php echo $download; ?></a></p> 
    <?php } ?> 
    <table style="border-collapse: collapse; width: 100%; border-top: 1px solid #DDDDDD; border-left: 1px solid #DDDDDD; margin-bottom: 20px;"> 
    <thead> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;" colspan="2"><?php echo $text_order_detail; ?></td> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"><b><?php echo $text_order_id; ?></b> <?php echo $order_id; ?><br /> 
      <b><?php echo $text_date_added; ?></b> <?php echo $date_added; ?><br /> 
      <b><?php echo $text_payment_method; ?></b> <?php echo $payment_method; ?><br /> 
      <?php if ($shipping_method) { ?> 
      <b><?php echo $text_shipping_method; ?></b> <?php echo $shipping_method; ?> 
      <?php } ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"><b><?php echo $text_email; ?></b> <?php echo $email; ?><br /> 
      <b><?php echo $text_telephone; ?></b> <?php echo $telephone; ?><br /> 
      <b><?php echo $text_ip; ?></b> <?php echo $ip; ?><br /> 
      <b><?php echo $text_order_status; ?></b> <?php echo $order_status; ?><br /></td> 
     </tr> 
    </tbody> 
    </table> 
    <?php if ($comment) { ?> 
    <table style="border-collapse: collapse; width: 100%; border-top: 1px solid #DDDDDD; border-left: 1px solid #DDDDDD; margin-bottom: 20px;"> 
    <thead> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;"><?php echo $text_instruction; ?></td> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"><?php echo $comment; ?></td> 
     </tr> 
    </tbody> 
    </table> 
    <?php } ?> 
    <table style="border-collapse: collapse; width: 100%; border-top: 1px solid #DDDDDD; border-left: 1px solid #DDDDDD; margin-bottom: 20px;"> 
    <thead> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;"><?php echo $text_payment_address; ?></td> 
     <?php if ($shipping_address) { ?> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;"><?php echo $text_shipping_address; ?></td> 
     <?php } ?> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"><?php echo $payment_address; ?></td> 
     <?php if ($shipping_address) { ?> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"><?php echo $shipping_address; ?></td> 
     <?php } ?> 
     </tr> 
    </tbody> 
    </table> 
    <table style="border-collapse: collapse; width: 100%; border-top: 1px solid #DDDDDD; border-left: 1px solid #DDDDDD; margin-bottom: 20px;"> 
    <thead> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;"><?php echo $text_product; ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: left; padding: 7px; color: #222222;"><?php echo $text_model; ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: right; padding: 7px; color: #222222;"><?php echo $text_quantity; ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: right; padding: 7px; color: #222222;"><?php echo $text_price; ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; background-color: #EFEFEF; font-weight: bold; text-align: right; padding: 7px; color: #222222;"><?php echo $text_total; ?></td> 
     </tr> 
    </thead> 
    <tbody> 
     <?php foreach ($products as $product) { ?> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"><?php echo $product['name']; ?> 
      <?php foreach ($product['option'] as $option) { ?> 
      <br /> 
      &nbsp;<small> - <?php echo $option['name']; ?>: <?php echo $option['value']; ?></small> 
      <?php } ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"><?php echo $product['model']; ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;"><?php echo $product['quantity']; ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;"><?php echo $product['price']; ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;"><?php echo $product['total']; ?></td> 
     </tr> 
     <?php } ?> 
     <?php foreach ($vouchers as $voucher) { ?> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"><?php echo $voucher['description']; ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: left; padding: 7px;"></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;">1</td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;"><?php echo $voucher['amount']; ?></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;"><?php echo $voucher['amount']; ?></td> 
     </tr> 
     <?php } ?> 
    </tbody> 
    <tfoot> 
     <?php foreach ($totals as $total) { ?> 
     <tr> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;" colspan="4"><b><?php echo $total['title']; ?>:</b></td> 
     <td style="font-size: 12px; border-right: 1px solid #DDDDDD; border-bottom: 1px solid #DDDDDD; text-align: right; padding: 7px;"><?php echo $total['text']; ?></td> 
     </tr> 
     <?php } ?> 
    </tfoot> 
    </table> 
    <p style="margin-top: 0px; margin-bottom: 20px;"><?php echo $text_footer; ?></p> 
</div> 
</body> 
</html> 

Versuchen Sie nun etwas von einer Website zu bestellen und es sollte funktionieren.

Verwandte Themen