HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/topswtw.komma.pro/app/KommaApp/Shop/Mailers/AdminMailer.php
<?php


namespace KommaApp\Shop\Mailers;


use Illuminate\Support\Facades\Input;
use KommaApp\Shop\Orders\Order;
use KommaApp\Shop\Orders\OrderProduct;

class AdminMailer extends Mailer
{
    public function sendTo($email, $subject, $view, $data = [], $attachment = null, $attachmentName = 'invoice.pdf', $replyEmail = null, $replyName = null)
    {
        $this->customFrom();

        parent::sendTo($email, $subject, $view, $data, $attachment, $attachmentName, $replyEmail, $replyName);
    }

    /**
     * Set A different From address/shop
     *
     */
    public function customFrom()
    {

        //No order check if there is an email for the current domain country
        if (\Config::has('mail.shop_from.' . \Shop::getDomainCountry())) {
            $from = \Config::get('mail.shop_from.' . \Shop::getDomainCountry());
            //Set the from address and the from name
            $this->setFrom($from['address'], $from['name']);
            return $from;

        }

        if (isset(\Config::get('mail.shop_from')[\Shop::getShop()->id])) {
            $from = \Config::get('mail.shop_from')[\Shop::getShop()->id];
            $this->setFrom($from['address'], $from['name']);
            return $from;
        }
    }


    public function sendContactForm($data)
    {
        $view = 'emails.contact.contact';


        $to = \Config::get('mail.from')['address'];
        if(\Config::has('mail.shop_from.'.\Shop::getDomainCountry()))   $to = \Config::get('mail.shop_from.'.\Shop::getDomainCountry())['address'];

        $data['website'] = \Shop::getDomain()->get();

        $subject = \Lang::get('emails/customer/contact.subject', ['website' => $data['website']]);
        $data['message_text'] = $data['message'];

        return $this->sendTo($to, $subject, $view, $data, null, null, $data['email'], $data['name']);
    }


    public function sendRetourFormToAdminAndCustomer($data)
    {
        $view = 'emails.contact.return';

        $data['website'] = \Shop::getDomain()->get();

        $orderNumber = $data['ordernumber'];

        /** @var Order|null $order */
        $order = Order::where('order_number', '=', $orderNumber)->first();
        $orderProducts = $order->products()->get();

        if(isset($data['return_checkbox'])) {
            $orderProducts = $orderProducts->map(function (OrderProduct $orderProduct) use ($data) {
                if (!in_array($orderProduct->internal_article_number, $data['return_checkbox'], true)) {
                    return null;
                }

                return [
                    'internal_article_number' => $orderProduct->internal_article_number,
                    'title' => $orderProduct->title
                ];
            })->filter(function ($arrayOrNull) {
                return ($arrayOrNull !== null);
            });
        } else {
            $orderProducts = [];
        }

        $name = [];
        $name[] = ucfirst($order['invoice_first_name']);
        $name[] = $order['invoice_name_insertion'];
        $name[] = ucfirst($order['invoice_last_name']);

        $data['name'] = implode(' ', $name);
        $data['customer_email'] = $order['invoice_email'];
        $data['order_products'] = $orderProducts;

        $toCustomer = $order['invoice_email'];

        $toAdmin = \Config::get('mail.from')['address'];
        if(\Config::has('mail.shop_from.'.\Shop::getDomainCountry())) $toAdmin = \Config::get('mail.shop_from.'.\Shop::getDomainCountry())['address'];

        $subject = \Lang::get('emails/customer/return.subject', ['website' => $data['website']]);

        $photoPath = null;
        $photoName = null;
        $uploadedFile = null;
        if(\Input::file('damagedfilterphoto'))
        {
            $uploadedFile = \Input::file('damagedfilterphoto');
            $photoName = 'return_damage_'.$data['ordernumber'].'.'.$uploadedFile->getClientOriginalExtension();
        }
        elseif(\Input::file('unknownfilterphoto'))
        {
            $uploadedFile = \Input::file('unknownfilterphoto');
            $photoName = 'return_unknown_'.$data['ordernumber'].'.'.$uploadedFile->getClientOriginalExtension();
        }

        if($uploadedFile)
        {
            $photoPath = $uploadedFile->getRealPath();
        }

        $this->sendTo($toAdmin, $subject, $view, $data, $photoPath, $photoName, $toCustomer, $toCustomer);
        $this->sendTo($toCustomer, $subject, $view, $data, $photoPath, $photoName, null, null);
    }

    public function sendAskHelpForm($data){
        $view = 'emails.contact.askHelp';
        $data['website'] = \Shop::getDomain()->get();
        $subject = \Lang::get('emails/customer/askHelp.subject', ['website' => $data['website']]);

        $this->sendMailFromView($view, $subject,$data);
    }

    public function sendMailFromView($view,$subject, $data){

        $to = \Config::get('mail.from')['address'];

        if (\Config::has('mail.shop_from.' . \Shop::getDomainCountry())) $to = \Config::get('mail.shop_from.' . \Shop::getDomainCountry())['address'];

        return $this->sendTo($to, $subject, $view, $data, null, null, $data['email'], $data['name']);
    }

    public function sendMaintenanceOrderReceived($data)
    {

        $subject = \Lang::get('pages/maintenance.admin_email.subject') . ' (' . \Lang::get('emails/order/received.content.orderNumber') . ': ' . $data['order_number'] . ')';
        $view = 'emails.maintenance.received_admin';

        $data['customer'] = $data->customer;

        $data['invoice_title'] = ($data['customer']->gender == 'male' ? 'mr' : 'ms');
        $to = \Config::get('komma/tops.maintenance_emails');
        return $this->sendTo($to, $subject, $view, $data->toArray());

    }

}