floko

Oxid Hack Email.php - sendOrderEmailToUser

Aug 30th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.63 KB | None | 0 0
  1. /*
  2. ==========================================================================================================================================
  3. Eingefügter Teil/Inserted Part (A):
  4. ==========================================================================================================================================
  5. */
  6.  
  7. $attachment_path = "";
  8. $sFilename = "";
  9.                
  10. $soxId = $order->oxorder__oxid->value;
  11.        
  12.            
  13. if ( $soxId != "-1" && isset( $soxId))
  14. {                                  
  15.     // load object                        
  16.    
  17.     $oOrder2 = oxNew( "oxorder" );                
  18.     $oOrder2->load( $soxId);
  19.                            
  20.     // make file name harder to guess by adding md5(element)
  21.     $sFilename  = $oOrder2->oxorder__oxordernr->value.'-'.$oOrder2->oxorder__oxbilllname->value.'-'.md5($oOrder2->oxorder__oxbilllname->value).'.pdf';
  22.  
  23.     ob_start();                        
  24.    
  25.     $language = \OxidEsales\Eshop\Core\Registry::getLang();
  26.     $orderLanguage = $language->getObjectTplLanguage();
  27.    
  28.     // Please note: cust_lang.php has to be extended manually with the content of
  29.     // /source/modules/oe/invoicepdf/views/admin/de/invoicepdf_lang.php
  30.     // (ORDER_OVERVIEW_PDF* placeholders)
  31.                                        
  32.     $oOrder2->genPDF($sFilename, $orderLanguage);            
  33.                    
  34.     $sPDF = ob_get_contents();
  35.     ob_end_clean();                
  36.                                  
  37.     $sAttPath = "inv/";
  38.    
  39.     //$attachment_path = oxRegistry::get("oxUtilsFile")->normalizeDir($sAttPath);
  40.     $attachment_path = "/srv/www/####YOURVHOSTHERE###/source/out/media/";  //try hard coded first, you may want to specify a different folder                              
  41.    
  42.     $fp = fopen($attachment_path.$sFilename,"w+");
  43.     fwrite($fp, $sPDF);
  44.     fclose($fp);                                    
  45.  
  46.     // PDF is created, attach to e-mail further below...          
  47.    
  48.     // remove dated invoice pdf files
  49.     $days = 0.5;                        
  50.     $dir = substr($attachment_path, 0, strlen($attachment_path)-1);                              
  51.    
  52.     if ($handle = opendir($dir))
  53.     {
  54.                    
  55.         while (false !== ($file = readdir($handle)))
  56.       {    
  57.            
  58.             if ($file[0] == '.' || is_dir($dir.'/'.$file))
  59.         {
  60.                 continue;
  61.             }
  62.            
  63.             $ext = substr(strrchr($file, '.'), 1);
  64.            
  65.             if ($ext == "pdf" && (time() - filemtime($dir.'/'.$file)) > ($days *86400))
  66.         {      
  67.                 error_log("deleting dated invoice file: " . $dir.'/'.$file);
  68.                 unlink($dir.'/'.$file);
  69.             }
  70.            
  71.         }
  72.         closedir($handle); 
  73.     }
  74.     // /remove dated invoice pdf files    
  75.  
  76. /*
  77. ==========================================================================================================================================
  78. Eingefügter Teil/Inserted Part (B):
  79. ==========================================================================================================================================
  80. */
  81. if ($sFilename != "")
  82. {
  83.   $sFullPath = $attachment_path.$sFilename;
  84.   if ( @is_readable( $sFullPath ) && @is_file( $sFullPath ) )
  85.   {        
  86.     parent::addAttachment( $sFullPath );                                                                    
  87.     error_log ("OK, attached PDF to e-mail!");
  88.   } else {
  89.     error_log ("problems attaching invoice pdf to mail - file not found: " . $sFullPath);
  90.   }
  91.        
  92. }  
  93. ================================================================================================================================================================
Add Comment
Please, Sign In to add comment