2016-11-11 2 views
1

CMS: Opencartopencart - php Créer un fichier Excel avec des détails de la commande et l'envoyer par email

Langue: PHP

type de site Web: e-commerce avec les paiements en ligne et les produits

Problème: Sur le client qui commande un produit, la feuille Excel doit être générée et envoyée par e-mail à une société de livraison et propriétaire du magasin

Ce que j'ai accompli: J'ai écrit le code pour générer la feuille Excel et l'enregistrer sur le serveur, le lien vers ae La feuille de xcel sera alors envoyée par email. J'ai également trouvé le fichier sur le serveur qui est responsable de l'action qui procède à la commande.

code

pour créer une feuille Excel:

<?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; 
    ?> 

Le fichier sur opencart est situé dans: public_html/catalogue/modèle/caisse/order.php

Probablement je besoin d'intégrer le code de création un excel sur une partie du fichier où il envoie un email sur l'ordre de stocker le propriétaire pour avoir le même contenu.

Code order.php: http://ideone.com/pYcR18

+1

l'exemple de code dans ce lien a une mise en forme godawful. Effacez-le pour qu'il soit plus facile à lire. – Takarii

+0

@takarii J'ai besoin de trouver dans ce fichier où intégrer le code qui va créer un fichier Excel –

+0

@shadyyx pouvez-vous m'aider avec s'il vous plaît. –

Répondre

2

Ok, qui était beaucoup plus facile que je m'y attendais. Comme personne n'y a prêté attention, j'ai passé quelques heures à chercher et à trouver une solution. Donc, si quelqu'un a besoin de générer un fichier Excel qui doivent être envoyés à la société de livraison, la voici:

Ouvert si public_html/système/stockage/modification/catalogue/modèle/caisse/order.php

ou public_html/catalog/model/checkout/order.php cause pour certaines personnes le 2ème lien a fonctionné mais pour moi le 1er lien a fonctionné.

Rechercher ceci:

// Admin Alert Mail 

puis faites défiler vers le bas jusqu'à ce:

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

collez ce code pour générer le fichier Excel:

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

Aller à public_html/Catalogue/view/theme/default/template/mail/et crée un fichier excel.tpl.

Collez ce à 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> 

maintenant essayer de commander quelque chose à partir d'un site Web et il devrait fonctionner.