only send emails when configured so

This commit is contained in:
Herbert Maschke 2020-02-17 16:52:58 +01:00
parent cdc292c196
commit b0e37edd63
6 changed files with 65 additions and 18 deletions

View File

@ -186,6 +186,11 @@ return [
'title' => 'admin::app.admin.emails.notifications.verification',
'type' => 'boolean',
],
[
'name' => 'emails.general.notifications.registration',
'title' => 'admin::app.admin.emails.notifications.registration',
'type' => 'boolean',
],
[
'name' => 'emails.general.notifications.customer',
'title' => 'admin::app.admin.emails.notifications.customer',

View File

@ -120,7 +120,10 @@ class CustomerController extends Controller
$customer = $this->customerRepository->create($data);
try {
Mail::queue(new NewCustomerNotification($customer, $password));
$configKey = 'emails.general.notifications.emails.general.notifications.customer';
if (core()->getConfigData($configKey)) {
Mail::queue(new NewCustomerNotification($customer, $password));
}
} catch (\Exception $e) {
report($e);
}

View File

@ -28,9 +28,15 @@ class Order
public function sendNewOrderMail($order)
{
try {
Mail::queue(new NewOrderNotification($order));
$configKey = 'emails.general.notifications.emails.general.notifications.new-order';
if (core()->getConfigData($configKey)) {
Mail::queue(new NewOrderNotification($order));
}
Mail::queue(new NewAdminNotification($order));
$configKey = 'emails.general.notifications.emails.general.notifications.new-admin';
if (core()->getConfigData($configKey)) {
Mail::queue(new NewAdminNotification($order));
}
} catch (\Exception $e) {
report($e);
}
@ -48,7 +54,10 @@ class Order
return;
}
Mail::queue(new NewInvoiceNotification($invoice));
$configKey = 'emails.general.notifications.emails.general.notifications.new-invoice';
if (core()->getConfigData($configKey)) {
Mail::queue(new NewInvoiceNotification($invoice));
}
} catch (\Exception $e) {
report($e);
}
@ -62,7 +71,10 @@ class Order
public function sendNewRefundMail($refund)
{
try {
Mail::queue(new NewRefundNotification($refund));
$configKey = 'emails.general.notifications.emails.general.notifications.new-refund';
if (core()->getConfigData($configKey)) {
Mail::queue(new NewRefundNotification($refund));
}
} catch (\Exception $e) {
report($e);
}
@ -80,9 +92,15 @@ class Order
return;
}
Mail::queue(new NewShipmentNotification($shipment));
$configKey = 'emails.general.notifications.emails.general.notifications.new-shipment';
if (core()->getConfigData($configKey)) {
Mail::queue(new NewShipmentNotification($shipment));
}
Mail::queue(new NewInventorySourceNotification($shipment));
$configKey = 'emails.general.notifications.emails.general.notifications.new-inventory-source';
if (core()->getConfigData($configKey)) {
Mail::queue(new NewInventorySourceNotification($shipment));
}
} catch (\Exception $e) {
report($e);
}
@ -95,7 +113,10 @@ class Order
public function sendCancelOrderMail($order)
{
try {
Mail::queue(new CancelOrderNotification($order));
$configKey = 'emails.general.notifications.emails.general.notifications.cancel-order';
if (core()->getConfigData($configKey)) {
Mail::queue(new CancelOrderNotification($order));
}
} catch (\Exception $e) {
report($e);
}

View File

@ -1211,6 +1211,7 @@ return [
'notification_label' => 'Notifications',
'notifications' => [
'verification' => 'Send verification E-mail',
'registration' => 'Send registration E-mail',
'customer' => 'Send customer E-mail',
'new-order' => 'Send Order Confirmation E-mail',
'new-admin' => 'Send Admin Invitation E-mail',

View File

@ -36,6 +36,16 @@ class ConfigTableSeeder extends Seeder
DB::table('core_config')->insert([
'id' => 3,
'code' => 'emails.general.notifications.emails.general.notifications.registration',
'value' => '1',
'channel_code' => null,
'locale_code' => null,
'created_at' => $now,
'updated_at' => $now,
]);
DB::table('core_config')->insert([
'id' => 4,
'code' => 'emails.general.notifications.emails.general.notifications.customer',
'value' => '1',
'channel_code' => null,

View File

@ -31,23 +31,24 @@ class RegistrationController extends Controller
* CustomerRepository object
*
* @var Object
*/
*/
protected $customerRepository;
/**
* CustomerGroupRepository object
*
* @var Object
*/
*/
protected $customerGroupRepository;
/**
* Create a new Repository instance.
*
* @param \Webkul\Customer\Repositories\CustomerRepository $customer
* @param \Webkul\Customer\Repositories\CustomerGroupRepository $customerGroupRepository
* @param \Webkul\Customer\Repositories\CustomerRepository $customer
* @param \Webkul\Customer\Repositories\CustomerGroupRepository $customerGroupRepository
*
* @return void
*/
*/
public function __construct(
CustomerRepository $customerRepository,
CustomerGroupRepository $customerGroupRepository
@ -79,9 +80,9 @@ class RegistrationController extends Controller
{
$this->validate(request(), [
'first_name' => 'string|required',
'last_name' => 'string|required',
'email' => 'email|required|unique:customers,email',
'password' => 'confirmed|min:6|required',
'last_name' => 'string|required',
'email' => 'email|required|unique:customers,email',
'password' => 'confirmed|min:6|required',
]);
$data = request()->input();
@ -110,7 +111,10 @@ class RegistrationController extends Controller
if ($customer) {
if (core()->getConfigData('customer.settings.email.verification')) {
try {
Mail::queue(new VerificationEmail($verificationData));
$configKey = 'emails.general.notifications.emails.general.notifications.verification';
if (core()->getConfigData($configKey)) {
Mail::queue(new VerificationEmail($verificationData));
}
session()->flash('success', trans('shop::app.customer.signup-form.success-verify'));
} catch (\Exception $e) {
@ -119,7 +123,10 @@ class RegistrationController extends Controller
}
} else {
try {
Mail::queue(new RegistrationEmail(request()->all()));
$configKey = 'emails.general.notifications.emails.general.notifications.registration';
if (core()->getConfigData($configKey)) {
Mail::queue(new RegistrationEmail(request()->all()));
}
session()->flash('success', trans('shop::app.customer.signup-form.success-verify')); //customer registered successfully
} catch (\Exception $e) {