Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function sendAndCloseOrder($customer_id, $order_sequence)
- {
- $mail_data = [
- 'order_sequence' => $order_sequence,
- 'to'=>'r.gjorgjevska@gmail.com',
- 'subject'=>$server . $customer->title . ' WO 2.0 Hübscher order confirmation',
- 'notice_message'=>'',
- 'bcc'=>array(),
- 'cc'=>array(),
- 'from'=> $server . 'WO 2.0 Hübscher order confirmation',
- 'from_mail' => 'info@huebscherhemden.ch'
- ];
- $customer_mail_data = [
- 'order_sequence' => $order_sequence,
- 'to'=>'r.gjorgjevska@gmail.com',
- 'subject'=>$server . $customer->title . ' WO 2.0 Hübscher order customer confirmation',
- 'notice_message'=>'',
- 'bcc'=>array(),
- 'cc'=>array(),
- 'from'=> $server . 'WO 2.0 Hübscher order customer confirmation',
- 'from_mail' => 'info@huebscherhemden.ch'
- ];
- $mail_template_data = [
- 'notice_message' => ""
- ];
- if(App::environment() == 'wo_live') {
- if($merchant["mail_business"]) {
- if($merchant['confirmation_email_mode'] == 1) {
- $mail_data['to'] = Session::get('user.title');
- } else {
- if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
- $mail_data['to'] = "confirmation.mails@huebscherorder.com";
- } else {
- $mail_data['to'] = $merchant["mail_business"];
- }
- }
- } else {
- $mail_data['to'] = 'confirmation.mails@huebscherorder.com';
- $mail_data['subject'] = $server . $customer->title . ' WO 2.0 Hübscher order confirmation - merchant email address does not exist in main contact';
- $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 />";
- }
- $customer_mail_data['bcc'] = Config::get('order_mails.bcc');
- $mail_data['bcc'] = Config::get('order_mails.bcc');
- if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
- foreach($customer_addresses as $k=>$v) {
- if($v->contactentries_docref_sequence == 1) {
- if($v->mail_private != '') {
- $customer_mail_data['to'] = $v->mail_private;
- } else {
- if($v->mail_business != '') {
- $customer_mail_data['to'] = $v->mail_business;
- }
- }
- break;
- }
- }
- }
- } else {
- if($merchant["mail_business"]) {
- if($merchant['confirmation_email_mode'] == 1) {
- $mail_data['to'] = Session::get('user.title');
- } else {
- $mail_data['to'] = 'goran@gtostudio.com';
- }
- } else {
- $mail_data['to'] = 'confirmation.mails@huebscherorder.com';
- $mail_data['subject'] = $server .$customer->title . ' WO 2.0 Hübscher order confirmation - merchant email address does not exist in main contact';
- $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 />";
- }
- if(App::environment() == "local") {
- $mail_data["from_mail"] = "goran.despotoski.development@gmail.com";
- $customer_mail_data["from_mail"] = "goran.despotoski.development@gmail.com";
- }
- $customer_mail_data['cc'] = Config::get('order_mails.bcc');
- $mail_data['cc'] = Config::get('order_mails.bcc');
- if(($customer_id == 118004 && App::environment() == "avalop")) {
- if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
- foreach($customer_addresses as $k=>$v) {
- if($v->contactentries_docref_sequence == 1) {
- if($v->mail_private != '') {
- $customer_mail_data['to'] = $v->mail_private;
- } else {
- if($v->mail_business != '') {
- $customer_mail_data['to'] = $v->mail_business;
- }
- }
- break;
- }
- }
- }
- }
- if(($customer_id == 110465 && App::environment() == "local")) {
- if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
- foreach($customer_addresses as $k=>$v) {
- if($v->contactentries_docref_sequence == 1) {
- if($v->mail_private != '') {
- $customer_mail_data['to'] = $v->mail_private;
- } else {
- if($v->mail_business != '') {
- $customer_mail_data['to'] = $v->mail_business;
- }
- }
- break;
- }
- }
- }
- }
- }
- //dd($mail_data);
- try {
- Mail::send('emails.order_confirmation', $mail_template_data, function($message) use ($mail_data, $customer)
- {
- $message->from($mail_data['from_mail'], $mail_data['from']);
- $message->to('r.gjorgjevska@gmail.com');
- $message->subject($mail_data['subject']);
- foreach ($mail_data['bcc'] as $v) {
- $message->bcc($v);
- }
- foreach ($mail_data['cc'] as $v) {
- $message->cc($v);
- }
- $message->attach(storage_path().'/pdfs/'.$mail_data['order_sequence'].'.pdf', ['as' => $mail_data['order_sequence']. ' ' . $customer->title . '.pdf']);
- });
- }catch(Swift_TransportException $e) {
- Log::error('Confirmation mail could not be sent', $e->getMessage());
- $query_string = "&status=mail_not_sent";
- }
- // dd($customer_mail_data);
- if(Session::get('user.merchant.docref.sequence') == Config::get('merchants.huebscher')) {
- try {
- Mail::send('emails.customer_order_confirmation', $mail_template_data, function($message) use ($customer_mail_data, $customer)
- {
- $message->from($customer_mail_data['from_mail'], $customer_mail_data['from']);
- $message->to('r.gjorgjevska@gmail.com');
- $message->subject($customer_mail_data['subject']);
- foreach ($customer_mail_data['bcc'] as $v) {
- $message->bcc($v);
- }
- foreach ($customer_mail_data['cc'] as $v) {
- $message->cc($v);
- }
- $message->attach(storage_path().'/pdfs/customer_order_'.$customer_mail_data['order_sequence'].'.pdf', ['as' => $customer_mail_data['order_sequence']. ' ' . $customer->title . '.pdf']);
- });
- }catch(Swift_TransportException $e) {
- Log::error('Confirmation mail to Huebscher private customer could not be sent', $e->getMessage());
- $query_string = "&status=mail_not_sent";
- }
- }
- if($debug_log) Log::info('7. Closing and sending order - after getBySequenceContactentries after mail sending before redirect');
- return Redirect::to('shop/customer/orders/success/'.$customer_id.'/'.$order_sequence . "?".$query_string);
- } else {
- if($debug_log) Log::info('Not an active order. DB returned nothing, redirecting user to success page for order: '. $order_sequence);
- return Redirect::to('shop/customer/orders/success/'.$customer_id.'/'.$order_sequence . "?".$query_string);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement