File: D:/HostingSpaces/SBogers10/topswtwmobile.komma.pro/app/KommaApp/Shop/Mailers/CustomerMailer.php
<?php
namespace KommaApp\Shop\Mailers;
class CustomerMailer extends Mailer
{
/**
* @param $orderData
* @return mixed
*/
public function sendOrderReceived($orderData)
{
$subject = \Lang::get('emails/order/received.subject') . ' (' . \Lang::get('emails/order/received.content.orderNumber') . ': ' . $orderData['order_number'] . ')';
$view = 'emails.order.received';
$userEmail = $orderData['invoice_email'];
$orderData['order']['customer'] = $orderData['order']->customer->toArray();
//subject_special
if (\Lang::has('emails/order/received.subject_special')) {
$subject = \Lang::get('emails/order/received.subject_special') . ' (' . \Lang::get('emails/order/received.content.orderNumber') . ': ' . $orderData['order_number'] . ')';
}
$this->customFrom($orderData);
return $this->sendTo($userEmail, $subject, $view, $orderData);
}
/**
* @param $order , Note this is the Order from kommaApp not KMs order
* @return mixed
*/
public function sendOrderPayed($order)
{
//Create data array
$data = $order->toArray();
$data['order'] = $order;
$from = $this->customFrom($order);
//use this because otherwise we cant set an attachment ?
$this->mail->alwaysFrom($from['address'], $from['name']);
//todo: Check if we can fix this filty method
$this->mail->queue('emails.order.payed', $data, function ($message) use ($data) {
$pdf = null;
$subject = \Lang::get('emails/order/payed.subject');
$subject .= ' (' . \Lang::get('emails/order/received.content.orderNumber') . ': ' . $data['order_number'] . ')';
$pdf = \PDF::loadView('pdfs.invoice', ['order' => $data['order']]);
$message->to($data['invoice_email'])->subject($subject);
if ($pdf) $message->attachData($pdf->output(), \Lang::get('pdfs/invoice.fileName', ['orderNumber' => $data['order_number']]) . '.pdf');
});
}
/**
* @param $orderData
* @return mixed
*/
public function sendOrderShipped($orderData)
{
$subject = \Lang::get('emails/order/shipped.subject') . ' (' . \Lang::get('emails/order/received.content.orderNumber') . ': ' . $orderData['order_number'] . ')';;
$view = 'emails.order.shipped';
$userEmail = $orderData['invoice_email'];
$this->customFrom($orderData);
return $this->sendTo($userEmail, $subject, $view, $orderData);
}
/**
* This wil send the email for the special sendings
* like partly shipped, partly shipped last
*
* @param $orderData
* @return mixed
*
*/
public function sendOrderShippedSpecial($orderData, $status)
{
//todo:: put the correct emails in
$subject = \Lang::get('emails/order/shipped.' . $status . '.subject', ['orderNummer' => \Lang::get('emails/order/received.content.orderNumber') . ': ' . $orderData['order_number']]);
$view = 'emails.order.shipped_special';
$userEmail = $orderData['invoice_email'];
$orderData['status'] = $status;
$this->customFrom($orderData);
return $this->sendTo($userEmail, $subject, $view, $orderData);
}
/**
* Verify new customer
* @param $customerData
* @return mixed
*/
public function sendCustomerValidation($customerData)
{
$subject = \Lang::get('emails/customer/verify.subject');
$view = 'emails.customer.verify';
$userEmail = $customerData['email'];
$this->customFrom();
return $this->sendTo($userEmail, $subject, $view, $customerData);
}
/**
* Send customer a link to pay an open order
* @param $customerData
* @return mixed
*/
public function sendOpenOrderNotification($customerData)
{
$subject = \Lang::get('emails/order/open.subject', ['orderNumber' => $customerData['order_number']]);
$view = 'emails.order.open';
$userEmail = $customerData['invoice_email'];
$this->customFrom($customerData);
return $this->sendTo($userEmail, $subject, $view, $customerData);
}
/**
* Send customer a reminder with a link to pay an open order
* @param $customerData
* @return mixed
*/
public function sendOpenOrderReminder($customerData)
{
//not used at the moment
$subject = \Lang::get('emails/order/open.openReminder', ['orderNumber' => $customerData['order_number']]);
$view = 'emails.order.openReminder';
$userEmail = $customerData['invoice_email'];
$this->customFrom($customerData);
return $this->sendTo($userEmail, $subject, $view, $customerData);
}
public function sendOrderReceivedToShop($orderData)
{
$view = 'emails.order.received-shop';
$to = \Config::get('mail.from')['address'];
$orderData['shop_owner'] = 'Tops Team';
$subject = 'Bevestiging bestelling nr: ' . $orderData['order_number'];
$this->customFrom($orderData);
return $this->sendTo($to, $subject, $view, $orderData);
}
public function sendContactForm($data)
{
$view = 'emails.contact.contact';
$to = \Config::get('mail.from')['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);
}
/**
* Set A different From address/shop
*
*/
public function customFrom($order = null, $type = null)
{
//check if order is given
if ($order) {
//check if the mail.shop_form the domain country exists
if (\Config::has('mail.shop_from.' . $order['domain_country'])) {
$from = \Config::get('mail.shop_from.' . $order['domain_country']);
if ($type) $from = \Config::get('mail.' . $type . '_from.' . $order['domain_country']);
//Set the from address and the from name
$this->setFrom($from['address'], $from['name']);
return $from;
}
}
//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());
if ($type) $from = \Config::get('mail.' . $type . '_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;
}
}
/**ยง
* @param $order , Note this is the Order from kommaApp not KMs order
* @return mixed
*/
public function sendOwnerStockChange($shipmentId, $filePath)
{
$data = [
'shipmentId' => $shipmentId,
'filePath' => $filePath,
'invoice_email' => \Config::get('komma/tops.stock_emails')
];
//todo: Check if we can fix this filty method
$this->mail->queue('emails.shop.stock-file', $data, function ($message) use ($data) {
$pdf = null;
$subject = 'Stock wijziging na verzending nr:' . $data['shipmentId'];
$message->to($data['invoice_email'])->subject($subject);
$message->attach($data['filePath'], ['mime' => 'text/csv']);
});
}
public function sendMaintenanceOrderReceived($data)
{
// mooi($data->toArray());
$subject = \Lang::get('pages/maintenance.email.subject') . ' (' . \Lang::get('emails/order/received.content.orderNumber') . ': ' . $data['order_number'] . ')';
$view = 'emails.maintenance.received';
$userEmail = $data['invoice_email'];
$data['customer'] = $data->customer;
$data['invoice_title'] = ($data['customer']->gender == 'male' ? 'mr' : 'ms');
$this->customFrom($data, 'maintenance');
return $this->sendTo($userEmail, $subject, $view, $data->toArray());
}
/**
* @param $orderData
* @return mixed
*
* public function sendOrderProcessed($orderData)
* {
* $subject = 'Bevestiging ontvangst bestelling';
* $view = 'emails.order.processed';
*
* $userEmail = $orderData['invoice_email'];
* $orderId = $orderData['invoice_email'];
*
* return $this->sendTo($userEmail, $subject, $view,
* [
* 'orderId' => $orderId
* ]);
* }
*
* /**
* Doesn't work with generated PDF attachments..
*
* @param $orderData
* @return mixed
*
* public function sendOrderReceived($data)
* {
* $subject = 'Bevestiging ontvangst bestelling';
* $view = 'emails.order.received';
* $userEmail = $data['invoice_email'];
* $attachment = $data['invoice'];
*
* return $this->sendTo($userEmail, $subject, $view, $data, $attachment);
* }
*/
}