| 1 |  |  | <?php namespace Hideyo\Ecommerce\Framework\Services\Order\Events\Handlers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Hideyo\Ecommerce\Framework\Services\Order\Events\OrderChangeStatus; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Queue\InteractsWithQueue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Contracts\Queue\ShouldBeQueued; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Mail; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use File; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Hideyo\Ecommerce\Framework\Services\Invoice\InvoiceFacade as InvoiceService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Hideyo\Ecommerce\Framework\Services\GeneralSetting\GeneralSettingFacade as GeneralSettingService; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | class HandleOrderStatusEmail | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |      * Handle the event. | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * @param  OrderChangeStatus  $event | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public function handle(OrderChangeStatus $event) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         if($event->order->shop->wholesale) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |             if ($event->status->send_email_to_customer) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |                 if ($event->status->orderStatusEmailTemplate) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                     $destinationPath = storage_path() . "/app"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                     $orderStatusEmailFromResult = GeneralSettingService::selectOneByShopIdAndName($event->order->shop_id, 'order-status-email-from'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                     $orderStatusEmailFrom = '[email protected]'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                     if ($orderStatusEmailFromResult) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                         $orderStatusEmailFrom = $orderStatusEmailFromResult->value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |                     $orderStatusEmailNameResult = GeneralSettingService::selectOneByShopIdAndName($event->order->shop_id, 'order-status-email-name'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                     $orderStatusEmailName = 'Phil & Phae B2B'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                     if ($orderStatusEmailNameResult) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                         $orderStatusEmailName = $orderStatusEmailNameResult->value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                     $orderStatusEmailBcc = '[email protected]'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                     $language = 'en'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                     if(strtoupper($event->order->orderBillAddress->country) == 'NL') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                         $language = 'nl'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                     }     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |              | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     Mail::send('frontend.email.order-status', ['content' => Cart::replaceTags($event->status->orderStatusEmailTemplate->translate($language)->content, $event->order)], function ($message) use ($event, $destinationPath, $orderStatusEmailFrom, $orderStatusEmailName, $orderStatusEmailBcc, $language) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                         $message->from($orderStatusEmailFrom, $orderStatusEmailName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                         $message->to($event->order->client->email, $event->order->orderBillAddress->firstname)->subject(Cart::replaceTags($event->status->orderStatusEmailTemplate->translate($language)->subject, $event->order)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                         if ($orderStatusEmailBcc) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                             $message->bcc($orderStatusEmailBcc, $orderStatusEmailName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                         if ($event->order and $event->status->attach_order_to_email) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                             $pdfText = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |                             $sign = '€'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |                             if($event->order->client->usd) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                                 $sign = '$'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                             $pdf = \PDF::loadView('admin.order.pdf-wholesale', array('order' => $event->order, 'sign' => $sign, 'pdfText' => $pdfText))->setPaper('a4', 'landscape');  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                             if (!File::exists($destinationPath.'/order/')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                                 File::makeDirectory($destinationPath.'/order/', 0777, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                             $upload_success = $pdf->save($destinationPath.'/order/order-'.$event->order->generated_custom_order_id.'.pdf'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                             $message->attach($destinationPath.'/order/order-'.$event->order->generated_custom_order_id.'.pdf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                             flash('Email has order attachment'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                         flash('Email with order status has been sent to '.$event->order->client->email.' from info@'.$orderStatusEmailFrom); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                     if ($event->status->attach_order_to_email) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                         File::delete($destinationPath.'/order/order-'.$event->order->generated_custom_order_id.'.pdf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 if($event->order->type == 'pre_order') { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                 }elseif($event->order->type == 'from_stock') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             if ($event->status->send_email_to_customer) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                 if ($event->status->orderStatusEmailTemplate) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                     $destinationPath = storage_path() . "/app"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                     $orderStatusEmailFromResult = GeneralSettingService::selectOneByShopIdAndName($event->order->shop_id, 'order-status-email-from'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                     $orderStatusEmailFrom = '[email protected]'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |                     if ($orderStatusEmailFromResult) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                         $orderStatusEmailFrom = $orderStatusEmailFromResult->value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                     $orderStatusEmailNameResult = GeneralSettingService::selectOneByShopIdAndName($event->order->shop_id, 'order-status-email-name'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                     $orderStatusEmailName = 'Phil & Phae'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                     if ($orderStatusEmailNameResult) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                         $orderStatusEmailName = $orderStatusEmailNameResult->value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                     $orderStatusEmailBccResult = GeneralSettingService::selectOneByShopIdAndName($event->order->shop_id, 'order-status-email-bcc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                     $orderStatusEmailBcc = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |                      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |                     if ($orderStatusEmailBccResult) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                         $orderStatusEmailBcc = $orderStatusEmailBccResult->value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                     $language = 'en'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                     if(strtoupper($event->order->orderBillAddress->country) == 'NL') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                         $language = 'nl'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                     }     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                     Mail::send('frontend.email.order-status', ['content' => Cart::replaceTags($event->status->orderStatusEmailTemplate->translate($language)->content, $event->order)], function ($message) use ($event, $destinationPath, $orderStatusEmailFrom, $orderStatusEmailName, $orderStatusEmailBcc, $language) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                         $message->from($orderStatusEmailFrom, $orderStatusEmailName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |                         $message->to($event->order->client->email, $event->order->orderBillAddress->firstname)->subject(Cart::replaceTags($event->status->orderStatusEmailTemplate->translate($language)->subject, $event->order)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |                         if ($orderStatusEmailBcc) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                             $message->bcc($orderStatusEmailBcc, $orderStatusEmailName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |                         if ($event->order->invoice and $event->status->attach_invoice_to_email) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |                             $pdf = \PDF::loadView('admin.invoice.pdf-consumer', array('invoice' => InvoiceService::find($event->order->invoice->id))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |                             if (!File::exists($destinationPath.'/invoice/')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |                                 File::makeDirectory($destinationPath.'/invoice/', 0777, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                             $upload_success = $pdf->save($destinationPath.'/invoice/invoice-'.$event->order->invoice->generated_custom_invoice_id.'.pdf'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |                             $message->attach($destinationPath.'/invoice/invoice-'.$event->order->invoice->generated_custom_invoice_id.'.pdf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |                             flash('Email has invoice attachment'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |                         if ($event->order and $event->status->attach_order_to_email) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                             $text = $this->sendingPaymentMethodRelated->selectOneByShopIdAndPaymentMethodIdAndSendingMethodId($event->order->shop->id, $event->order->orderPaymentMethod->payment_method_id, $event->order->orderSendingMethod->sending_method_id); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |                             $pdfText = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |                             if ($text) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |                                 $pdfText = Cart::replaceTags($text->pdf_text, $event->order); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |                             $pdf = \PDF::loadView('admin.order.pdf', array('order' => $event->order, 'pdfText' => $pdfText)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |                             if (!File::exists($destinationPath.'/order/')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                                 File::makeDirectory($destinationPath.'/order/', 0777, true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |                             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |                             $upload_success = $pdf->save($destinationPath.'/order/order-'.$event->order->generated_custom_order_id.'.pdf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |                             $message->attach($destinationPath.'/order/order-'.$event->order->generated_custom_order_id.'.pdf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |                             flash('Email has order attachment'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |                         flash('Email with order status has been sent to '.$event->order->client->email.' from info@'.$orderStatusEmailFrom); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |                     }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |                     if ($event->status->attach_invoice_to_email AND $event->order->invoice) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |                         File::delete($destinationPath.'/invoice/invoice-'.$event->order->invoice->generated_custom_invoice_id.'.pdf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |                     if ($event->status->attach_order_to_email) { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 168 |  |  |                         File::delete($destinationPath.'/order/order-'.$event->order->generated_custom_order_id.'.pdf'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 173 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 174 |  |  | } | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths