2016-11-11 7 views
1

로 보내 CMS : Opencartopencart - PHP를 위해 세부 사항을 가진 엑셀 파일을 작성하고 이메일

언어 : PHP

웹 사이트 유형 : 온라인 결제 및 제품

문제와 전자 상거래 : 고객이 제품을 주문할 때 Excel 시트를 작성하여 배달 회사와 상점 주인에게 전자 메일을 보내야합니다.

내가 수행 한 작업 : Excel 시트를 생성하여 서버에 저장하는 코드를 작성했습니다. ae에 링크 그러면 xcel 시트가 이메일로 전송됩니다. 주문을 진행하는 작업을 담당하는 서버에서도 파일을 발견했습니다.

엑셀 시트 만들기위한

코드 :

이 opencart에 파일이있는
<?php 
     $data = array(
      array("ORDER ID" => "here will be order id", "COMPANY NAME" => "name of the store", "ADDRESS LINE1" => "address of the customer", "ADDRESS LINE2" => "2nd address if filled","CONTACT PERSON"=>"Name of the customer","CITY" =>"City customer lives in", "PHONE_1"=>"phone","CONTENT" =>"a product name", "WH NUMBER" =>"the model number of product","PIECES"=>" amount ","COD"=>"can be left blank","AED"=>" and amount processed on order"), 
      ); 

     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 = "codexworld_export_data" . date('Ymd') . ".xls"; 

     // headers for download 




     $flag = false; 
     foreach($data 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); 
     } 

     exit; 
    ?> 

:으로 public_html/카탈로그/모델/체크 아웃/order.php

은 아마 내가 만드는 코드를 통합 할 필요를 파일의 일부분을 Excel에서 저장하고 소유자에게 동일한 내용의 주문에 대한 전자 메일을 보냅니다.

Order.php 코드 : http://ideone.com/pYcR18

+1

해당 링크의 코드 샘플에는 멋진 형식이 있습니다. 그것을 지우기 쉽게 읽을 수 있도록. – Takarii

+0

@takarii 파일을 어디서 찾을 수 있습니까? –

+0

@shadyyx 파일을 만드는 코드를 어디에서 찾을 수 있습니까? –

답변

2

좋아, 그건 내가 기대했던 것보다 훨씬 쉽게했다. 아무도 관심을 기울이지 않아서 2 시간 동안 연구하고 해결책을 찾았습니다. 누군가가 배달 회사에 전송해야하는 엑셀 파일을 생성 할 필요가있는 경우 그래서, 여기있다 :

열기 여부 public_html을/시스템/저장/수정/카탈로그/모델/체크 아웃/order.php

또는 public_html/catalog/model/checkout/order.php 어떤 사람들에게는 두 번째 링크가 작동했지만 첫 번째 링크는 작동했습니다. 이것에 대한

검색 :

// Admin Alert Mail 

다음이 때까지 아래로 스크롤 :

$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(); 

엑셀 파일 생성이 코드를 붙여 : public_html을 위해

//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(); 

이동/카탈로그// theme/default/template/mail /을보고 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> 

지금 웹 사이트에서 무언가를 주문하려고하고 그것을 작동합니다 :

것은이 excel.tpl 넣습니다.