File: D:/HostingSpaces/SBogers85/equichecker.com/app/KommaApp/Customers/CustomerNotifierService.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma Mediadesign
*/
namespace KommaApp\Customers;
use Carbon\Carbon;
use KommaApp\Site\Mailers\CustomerMailer;
use KommaApp\Orders\Models\Order;
use KommaApp\Sites\Models\Domain;
use KommaApp\Sites\Models\Site;
class CustomerNotifierService
{
/**
* @var Customer
*/
protected $customerModel;
/**
* @var CustomerMailer
*/
protected $customerMailer;
function __construct(Customer $customerModel, CustomerMailer $customerMailer)
{
$this->customerModel = $customerModel;
$this->customerMailer = $customerMailer;
}
/**
* This method will hande the notify mails
*
*/
public function notify()
{
//Load the orders available for the first reminder (notification)
$orders = $this->getOrdersForFirstNotification();
foreach ($orders as $order) {
$this->sendOpenOrderNotifications($order);
}
//
// // Open the orders available for the soccend reminder (Reminder)
// $orders = $this->getOrdersForSeccondNotification();
// foreach ($orders as $order) {
// $this->sendOpenOrderReminders($order);
//
// }
}
protected function getOrdersForNotification()
{
return Order::getUnnotifiedOpenOrders();
}
protected function getOrdersForFirstNotification()
{
return Order::getOrdersForFirstNotification();
}
protected function getOrdersForSeccondNotification()
{
return Order::getOrdersForSeccondNotification();
}
protected function getOrdersForReminder()
{
return Order::getNotifiedOpenOrders();
}
protected function sendOpenOrderNotifications(Order $order)
{
// Set the site language to the language of the order
\Site::setLanguageService($order->language_id);
//todo get the domain dynamicly
// Get the domain of site where the order has been placed
$data = $order->toArray();
$data['domain'] = 'https://www.' . Domain::where('site_id', '=', $order->site_id)->first()->domain;
// Send the mail
$this->customerMailer->sendOpenOrderNotification($data);
// Update Order record
$order->payment_open_notification_on = Carbon::now();
$order->save();
}
protected function sendOpenOrderReminders(Order $order)
{
// Set the site language to the language of the order
\Site::setLanguageService($order->language_id);
//todo get the domain dynamicly
// Get the domain of site where the order has been placed
$data = $order->toArray();
$data['domain'] = 'https://www.' . Domain::where('site_id', '=', $order->site_id)->first()->domain;
// Send the mail
$this->customerMailer->sendOpenOrderReminder($data);
// Update Order record
$order->payment_open_notification_reminder_on = Carbon::now();
$order->save();
}
}