Advertisement
Guest User

Untitled

a guest
Dec 28th, 2017
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.15 KB | None | 0 0
  1. public function sendAndCloseOrder($customer_id, $order_sequence)
  2.     {
  3.        
  4.             $mail_data = [
  5.                 'order_sequence' => $order_sequence,
  6.                 'to'=>'r.gjorgjevska@gmail.com',
  7.                 'subject'=>$server . $customer->title . ' WO 2.0 Hübscher order confirmation',
  8.                 'notice_message'=>'',
  9.                 'bcc'=>array(),
  10.                 'cc'=>array(),
  11.                 'from'=> $server . 'WO 2.0 Hübscher order confirmation',
  12.                 'from_mail' => 'info@huebscherhemden.ch'
  13.             ];
  14.            
  15.             $customer_mail_data = [
  16.                 'order_sequence' => $order_sequence,
  17.                 'to'=>'r.gjorgjevska@gmail.com',
  18.                 'subject'=>$server . $customer->title . ' WO 2.0 Hübscher order customer confirmation',
  19.                 'notice_message'=>'',
  20.                 'bcc'=>array(),
  21.                 'cc'=>array(),
  22.                 'from'=> $server . 'WO 2.0 Hübscher order customer confirmation',
  23.                 'from_mail' => 'info@huebscherhemden.ch'
  24.             ];
  25.            
  26.             $mail_template_data = [
  27.                 'notice_message' => ""
  28.             ];
  29.            
  30.             if(App::environment() == 'wo_live') {
  31.                 if($merchant["mail_business"]) {
  32.                     if($merchant['confirmation_email_mode'] == 1) {
  33.                         $mail_data['to'] = Session::get('user.title');
  34.                     } else {
  35.                         if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
  36.                             $mail_data['to'] = "confirmation.mails@huebscherorder.com";
  37.                         } else {
  38.                             $mail_data['to'] = $merchant["mail_business"];
  39.                         }
  40.                     }
  41.                 } else {
  42.                     $mail_data['to'] = 'confirmation.mails@huebscherorder.com';
  43.                     $mail_data['subject'] = $server . $customer->title . ' WO 2.0 Hübscher order confirmation - merchant email address does not exist in main contact';
  44.                     $mail_template_data['notice_message'] = "<b>This email has been sent to You because the merchant that made this order doesn't have an email associated with his main contact</b><br />";
  45.                 }
  46.                 $customer_mail_data['bcc'] = Config::get('order_mails.bcc');
  47.                 $mail_data['bcc'] = Config::get('order_mails.bcc');
  48.                
  49.                 if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
  50.                     foreach($customer_addresses as $k=>$v) {
  51.                         if($v->contactentries_docref_sequence == 1) {
  52.                             if($v->mail_private != '') {
  53.                                 $customer_mail_data['to'] = $v->mail_private;
  54.                             } else {
  55.                                 if($v->mail_business != '') {
  56.                                     $customer_mail_data['to'] = $v->mail_business;
  57.                                 }
  58.                             }
  59.                             break;
  60.                         }
  61.                     }
  62.                 }
  63.             } else {
  64.                 if($merchant["mail_business"]) {
  65.                     if($merchant['confirmation_email_mode'] == 1) {
  66.                         $mail_data['to'] = Session::get('user.title');
  67.                     } else {
  68.                         $mail_data['to'] = 'goran@gtostudio.com';
  69.                     }
  70.                 } else {
  71.                     $mail_data['to'] = 'confirmation.mails@huebscherorder.com';
  72.                     $mail_data['subject'] = $server .$customer->title . ' WO 2.0 Hübscher order confirmation - merchant email address does not exist in main contact';
  73.                     $mail_template_data['notice_message'] = "<b>This email has been sent to You because the merchant that made this order doesn't have an email associated with his main contact</b><br />";
  74.                 }
  75.                
  76.                 if(App::environment() == "local") {
  77.                     $mail_data["from_mail"] = "goran.despotoski.development@gmail.com";
  78.                     $customer_mail_data["from_mail"] = "goran.despotoski.development@gmail.com";
  79.                 }
  80.                
  81.                 $customer_mail_data['cc'] = Config::get('order_mails.bcc');
  82.                 $mail_data['cc'] = Config::get('order_mails.bcc');
  83.                
  84.                
  85.                 if(($customer_id == 118004 && App::environment() == "avalop")) {
  86.                     if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
  87.                         foreach($customer_addresses as $k=>$v) {
  88.                             if($v->contactentries_docref_sequence == 1) {
  89.                                 if($v->mail_private != '') {
  90.                                     $customer_mail_data['to'] = $v->mail_private;
  91.                                 } else {
  92.                                     if($v->mail_business != '') {
  93.                                         $customer_mail_data['to'] = $v->mail_business;
  94.                                     }
  95.                                 }
  96.                                 break;
  97.                             }
  98.                         }
  99.                     }
  100.                 }
  101.                 if(($customer_id == 110465 && App::environment() == "local")) {
  102.                     if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
  103.                         foreach($customer_addresses as $k=>$v) {
  104.                             if($v->contactentries_docref_sequence == 1) {
  105.                                 if($v->mail_private != '') {
  106.                                     $customer_mail_data['to'] = $v->mail_private;
  107.                                 } else {
  108.                                     if($v->mail_business != '') {
  109.                                         $customer_mail_data['to'] = $v->mail_business;
  110.                                     }
  111.                                 }
  112.                                 break;
  113.                             }
  114.                         }
  115.                     }
  116.                 }
  117.             }
  118.             //dd($mail_data);
  119.             try {
  120.                 Mail::send('emails.order_confirmation', $mail_template_data, function($message) use ($mail_data, $customer)
  121.                 {
  122.                     $message->from($mail_data['from_mail'], $mail_data['from']);
  123.  
  124.                     $message->to('r.gjorgjevska@gmail.com');
  125.                     $message->subject($mail_data['subject']);
  126.                     foreach ($mail_data['bcc'] as $v) {
  127.                         $message->bcc($v);
  128.                     }
  129.                     foreach ($mail_data['cc'] as $v) {
  130.                         $message->cc($v);
  131.                     }
  132.  
  133.                     $message->attach(storage_path().'/pdfs/'.$mail_data['order_sequence'].'.pdf', ['as' => $mail_data['order_sequence']. ' ' . $customer->title . '.pdf']);
  134.                 });
  135.             }catch(Swift_TransportException $e) {
  136.                 Log::error('Confirmation mail could not be sent', $e->getMessage());
  137.                 $query_string = "&status=mail_not_sent";
  138.             }
  139. //            dd($customer_mail_data);
  140.             if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
  141.                 try {
  142.                     Mail::send('emails.customer_order_confirmation', $mail_template_data, function($message) use ($customer_mail_data, $customer)
  143.                     {
  144.                         $message->from($customer_mail_data['from_mail'], $customer_mail_data['from']);
  145.  
  146.                         $message->to('r.gjorgjevska@gmail.com');
  147.                         $message->subject($customer_mail_data['subject']);
  148.                         foreach ($customer_mail_data['bcc'] as $v) {
  149.                             $message->bcc($v);
  150.                         }
  151.                         foreach ($customer_mail_data['cc'] as $v) {
  152.                             $message->cc($v);
  153.                         }
  154.  
  155.                         $message->attach(storage_path().'/pdfs/customer_order_'.$customer_mail_data['order_sequence'].'.pdf', ['as' => $customer_mail_data['order_sequence']. ' ' . $customer->title . '.pdf']);
  156.                     });
  157.                 }catch(Swift_TransportException $e) {
  158.                     Log::error('Confirmation mail to Huebscher private customer could not be sent', $e->getMessage());
  159.                     $query_string = "&status=mail_not_sent";
  160.                 }
  161.             }
  162.                
  163.             if($debug_log) Log::info('7. Closing and sending order  - after getBySequenceContactentries after mail sending before redirect');
  164.             return Redirect::to('shop/customer/orders/success/'.$customer_id.'/'.$order_sequence . "?".$query_string);
  165.         } else {
  166.             if($debug_log) Log::info('Not an active order. DB returned nothing, redirecting user to success page for order: '. $order_sequence);
  167.             return Redirect::to('shop/customer/orders/success/'.$customer_id.'/'.$order_sequence . "?".$query_string);
  168.         }
  169.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement