From ad76426fb564c7fcc0c21c072133c19a2dab9312 Mon Sep 17 00:00:00 2001 From: Vivek Date: Tue, 17 Mar 2020 16:10:47 +0530 Subject: [PATCH] [Updated: Shop & admin email setting added in configuration.] --- packages/Webkul/Admin/src/Config/system.php | 31 +++++++++++++++++ .../src/Mail/CancelOrderNotification.php | 7 ++-- .../Admin/src/Mail/NewAdminNotification.php | 7 ++-- .../src/Mail/NewCustomerNotification.php | 7 ++-- .../Mail/NewInventorySourceNotification.php | 7 ++-- .../Admin/src/Mail/NewInvoiceNotification.php | 7 ++-- .../Admin/src/Mail/NewOrderNotification.php | 7 ++-- .../Admin/src/Mail/NewRefundNotification.php | 7 ++-- .../src/Mail/NewShipmentNotification.php | 7 ++-- .../Admin/src/Resources/lang/ar/app.php | 5 +++ .../Admin/src/Resources/lang/en/app.php | 5 +++ .../Admin/src/Resources/lang/fa/app.php | 5 +++ .../Admin/src/Resources/lang/nl/app.php | 5 +++ .../Admin/src/Resources/lang/pt_BR/app.php | 5 +++ packages/Webkul/Core/src/Core.php | 34 +++++++++++++++++++ .../Customer/src/Mail/RegistrationEmail.php | 7 ++-- .../Customer/src/Mail/VerificationEmail.php | 17 +++++----- .../Notifications/CustomerResetPassword.php | 5 +-- .../Shop/src/Mail/SubscriptionEmail.php | 18 +++++----- .../src/Notifications/AdminResetPassword.php | 1 + 20 files changed, 148 insertions(+), 46 deletions(-) diff --git a/packages/Webkul/Admin/src/Config/system.php b/packages/Webkul/Admin/src/Config/system.php index 5e053eac5..e5c2dc139 100644 --- a/packages/Webkul/Admin/src/Config/system.php +++ b/packages/Webkul/Admin/src/Config/system.php @@ -30,6 +30,37 @@ return [ 'channel_based' => true, ], ], + ], [ + 'key' => 'general.general.email_settings', + 'name' => 'admin::app.admin.system.email-settings', + 'sort' => 1, + 'fields' => [ + [ + 'name' => 'sender_name', + 'title' => 'admin::app.admin.system.email-sender-name', + 'type' => 'text', + 'validation' => 'required|max:50', + 'channel_based' => true, + ], [ + 'name' => 'shop_email_from', + 'title' => 'admin::app.admin.system.shop-email-from', + 'type' => 'text', + 'validation' => 'required|email', + 'channel_based' => true, + ], [ + 'name' => 'admin_name', + 'title' => 'admin::app.admin.system.admin-name', + 'type' => 'text', + 'validation' => 'required|max:50', + 'channel_based' => true, + ], [ + 'name' => 'admin_email', + 'title' => 'admin::app.admin.system.admin-email', + 'type' => 'text', + 'validation' => 'required|email', + 'channel_based' => true, + ], + ], ], [ 'key' => 'general.content', 'name' => 'admin::app.admin.system.content', diff --git a/packages/Webkul/Admin/src/Mail/CancelOrderNotification.php b/packages/Webkul/Admin/src/Mail/CancelOrderNotification.php index b020bba9f..efdcb65d5 100644 --- a/packages/Webkul/Admin/src/Mail/CancelOrderNotification.php +++ b/packages/Webkul/Admin/src/Mail/CancelOrderNotification.php @@ -27,8 +27,9 @@ class CancelOrderNotification extends Mailable public function build() { - return $this->to($this->order->customer_email, $this->order->customer_full_name) - ->subject(trans('shop::app.mail.order.cancel.subject')) - ->view('shop::emails.sales.order-cancel'); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($this->order->customer_email, $this->order->customer_full_name) + ->subject(trans('shop::app.mail.order.cancel.subject')) + ->view('shop::emails.sales.order-cancel'); } } \ No newline at end of file diff --git a/packages/Webkul/Admin/src/Mail/NewAdminNotification.php b/packages/Webkul/Admin/src/Mail/NewAdminNotification.php index fd1426030..7329cbe35 100644 --- a/packages/Webkul/Admin/src/Mail/NewAdminNotification.php +++ b/packages/Webkul/Admin/src/Mail/NewAdminNotification.php @@ -36,8 +36,9 @@ class NewAdminNotification extends Mailable */ public function build() { - return $this->to(config('mail.admin.address')) - ->subject(trans('shop::app.mail.order.subject')) - ->view('shop::emails.sales.new-admin-order'); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to(core()->getAdminEmailDetails()['email']) + ->subject(trans('shop::app.mail.order.subject')) + ->view('shop::emails.sales.new-admin-order'); } } \ No newline at end of file diff --git a/packages/Webkul/Admin/src/Mail/NewCustomerNotification.php b/packages/Webkul/Admin/src/Mail/NewCustomerNotification.php index c80d68399..7a29f5484 100644 --- a/packages/Webkul/Admin/src/Mail/NewCustomerNotification.php +++ b/packages/Webkul/Admin/src/Mail/NewCustomerNotification.php @@ -49,8 +49,9 @@ class NewCustomerNotification extends Mailable */ public function build() { - return $this->to($this->customer->email) - ->subject(trans('shop::app.mail.customer.new.subject')) - ->view('shop::emails.customer.new-customer')->with(['customer' => $this->customer, 'password' => $this->password]); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($this->customer->email) + ->subject(trans('shop::app.mail.customer.new.subject')) + ->view('shop::emails.customer.new-customer')->with(['customer' => $this->customer, 'password' => $this->password]); } } \ No newline at end of file diff --git a/packages/Webkul/Admin/src/Mail/NewInventorySourceNotification.php b/packages/Webkul/Admin/src/Mail/NewInventorySourceNotification.php index 931d55a09..5ef23bd5e 100644 --- a/packages/Webkul/Admin/src/Mail/NewInventorySourceNotification.php +++ b/packages/Webkul/Admin/src/Mail/NewInventorySourceNotification.php @@ -40,8 +40,9 @@ class NewInventorySourceNotification extends Mailable $inventory = $this->shipment->inventory_source; - return $this->to($inventory->contact_email, $inventory->name) - ->subject(trans('shop::app.mail.shipment.subject', ['order_id' => $order->increment_id])) - ->view('shop::emails.sales.new-inventorysource-shipment'); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($inventory->contact_email, $inventory->name) + ->subject(trans('shop::app.mail.shipment.subject', ['order_id' => $order->increment_id])) + ->view('shop::emails.sales.new-inventorysource-shipment'); } } diff --git a/packages/Webkul/Admin/src/Mail/NewInvoiceNotification.php b/packages/Webkul/Admin/src/Mail/NewInvoiceNotification.php index a8bf2fba9..e7c45ce93 100755 --- a/packages/Webkul/Admin/src/Mail/NewInvoiceNotification.php +++ b/packages/Webkul/Admin/src/Mail/NewInvoiceNotification.php @@ -38,8 +38,9 @@ class NewInvoiceNotification extends Mailable { $order = $this->invoice->order; - return $this->to($order->customer_email, $order->customer_full_name) - ->subject(trans('shop::app.mail.invoice.subject', ['order_id' => $order->increment_id])) - ->view('shop::emails.sales.new-invoice'); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($order->customer_email, $order->customer_full_name) + ->subject(trans('shop::app.mail.invoice.subject', ['order_id' => $order->increment_id])) + ->view('shop::emails.sales.new-invoice'); } } diff --git a/packages/Webkul/Admin/src/Mail/NewOrderNotification.php b/packages/Webkul/Admin/src/Mail/NewOrderNotification.php index ca4b8c680..30c2e8101 100755 --- a/packages/Webkul/Admin/src/Mail/NewOrderNotification.php +++ b/packages/Webkul/Admin/src/Mail/NewOrderNotification.php @@ -36,8 +36,9 @@ class NewOrderNotification extends Mailable */ public function build() { - return $this->to($this->order->customer_email, $this->order->customer_full_name) - ->subject(trans('shop::app.mail.order.subject')) - ->view('shop::emails.sales.new-order'); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($this->order->customer_email, $this->order->customer_full_name) + ->subject(trans('shop::app.mail.order.subject')) + ->view('shop::emails.sales.new-order'); } } diff --git a/packages/Webkul/Admin/src/Mail/NewRefundNotification.php b/packages/Webkul/Admin/src/Mail/NewRefundNotification.php index 3e1d04bf6..3d7cb473c 100644 --- a/packages/Webkul/Admin/src/Mail/NewRefundNotification.php +++ b/packages/Webkul/Admin/src/Mail/NewRefundNotification.php @@ -38,8 +38,9 @@ class NewRefundNotification extends Mailable { $order = $this->refund->order; - return $this->to($order->customer_email, $order->customer_full_name) - ->subject(trans('shop::app.mail.refund.subject', ['order_id' => $order->increment_id])) - ->view('shop::emails.sales.new-refund'); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($order->customer_email, $order->customer_full_name) + ->subject(trans('shop::app.mail.refund.subject', ['order_id' => $order->increment_id])) + ->view('shop::emails.sales.new-refund'); } } diff --git a/packages/Webkul/Admin/src/Mail/NewShipmentNotification.php b/packages/Webkul/Admin/src/Mail/NewShipmentNotification.php index f18ab994e..ab7b65fd8 100755 --- a/packages/Webkul/Admin/src/Mail/NewShipmentNotification.php +++ b/packages/Webkul/Admin/src/Mail/NewShipmentNotification.php @@ -38,8 +38,9 @@ class NewShipmentNotification extends Mailable { $order = $this->shipment->order; - return $this->to($order->customer_email, $order->customer_full_name) - ->subject(trans('shop::app.mail.shipment.subject', ['order_id' => $order->increment_id])) - ->view('shop::emails.sales.new-shipment'); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($order->customer_email, $order->customer_full_name) + ->subject(trans('shop::app.mail.shipment.subject', ['order_id' => $order->increment_id])) + ->view('shop::emails.sales.new-shipment'); } } diff --git a/packages/Webkul/Admin/src/Resources/lang/ar/app.php b/packages/Webkul/Admin/src/Resources/lang/ar/app.php index 743e8c443..ee679f71d 100644 --- a/packages/Webkul/Admin/src/Resources/lang/ar/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/ar/app.php @@ -936,6 +936,11 @@ return [ 'footer-content' => 'Footer Text', 'locale-options' => 'Unit Options', 'weight-unit' => 'Weight Unit', + 'email-settings' => 'Email Settings', + 'email-sender-name' => 'Email Sender Name', + 'shop-email-from' => 'Shop Email Address [For sending emails]', + 'admin-name' => 'Admin Name', + 'admin-email' => 'Admin Email', 'admin-page-limit' => 'العناصر الافتراضية لكل صفحة (المشرف)', 'design' => 'Design', 'admin-logo' => 'Admin Logo', diff --git a/packages/Webkul/Admin/src/Resources/lang/en/app.php b/packages/Webkul/Admin/src/Resources/lang/en/app.php index 0fb8d7e25..a70827498 100755 --- a/packages/Webkul/Admin/src/Resources/lang/en/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/en/app.php @@ -1286,6 +1286,11 @@ return [ 'footer-toggle' => 'Toggle footer', 'locale-options' => 'Unit Options', 'weight-unit' => 'Weight Unit', + 'email-settings' => 'Email Settings', + 'email-sender-name' => 'Email Sender Name', + 'shop-email-from' => 'Shop Email Address [For sending emails]', + 'admin-name' => 'Admin Name', + 'admin-email' => 'Admin Email', 'admin-page-limit' => 'Default Items Per Page (Admin)', 'design' => 'Design', 'admin-logo' => 'Admin Logo', diff --git a/packages/Webkul/Admin/src/Resources/lang/fa/app.php b/packages/Webkul/Admin/src/Resources/lang/fa/app.php index ad9fc9d81..74bd33410 100644 --- a/packages/Webkul/Admin/src/Resources/lang/fa/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/fa/app.php @@ -1064,6 +1064,11 @@ return [ 'footer-content' => 'متن فوتر', 'locale-options' => 'گزینه های واحد', 'weight-unit' => 'واحد وزن', + 'email-settings' => 'Email Settings', + 'email-sender-name' => 'Email Sender Name', + 'shop-email-from' => 'Shop Email Address [For sending emails]', + 'admin-name' => 'Admin Name', + 'admin-email' => 'Admin Email', 'design' => 'طراحی', 'admin-logo' => 'لوگو مدیر', 'logo-image' => 'تصویر لوگو', diff --git a/packages/Webkul/Admin/src/Resources/lang/nl/app.php b/packages/Webkul/Admin/src/Resources/lang/nl/app.php index 1c096eaea..fc5f4ddb0 100644 --- a/packages/Webkul/Admin/src/Resources/lang/nl/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/nl/app.php @@ -1283,6 +1283,11 @@ return [ 'footer-toggle' => 'Toggle footer', 'locale-options' => 'Eenheid opties', 'weight-unit' => 'Gewichtseenheid', + 'email-settings' => 'Email Settings', + 'email-sender-name' => 'Email Sender Name', + 'shop-email-from' => 'Shop Email Address [For sending emails]', + 'admin-name' => 'Admin Name', + 'admin-email' => 'Admin Email', 'admin-page-limit' => 'Standaarditems per pagina (Admin)', 'design' => 'Ontwerp', 'admin-logo' => 'Admin Logo', diff --git a/packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php b/packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php index 8f6626468..ce6f38e7c 100755 --- a/packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php +++ b/packages/Webkul/Admin/src/Resources/lang/pt_BR/app.php @@ -1047,6 +1047,11 @@ return [ 'footer-content' => 'Texto de rodapé', 'locale-options' => 'Opções de unidade', 'weight-unit' => 'Unidade de peso', + 'email-settings' => 'Email Settings', + 'email-sender-name' => 'Email Sender Name', + 'shop-email-from' => 'Shop Email Address [For sending emails]', + 'admin-name' => 'Admin Name', + 'admin-email' => 'Admin Email', 'design' => 'Design', 'admin-logo' => 'Admin Logo', 'logo-image' => 'Logo Imagem', diff --git a/packages/Webkul/Core/src/Core.php b/packages/Webkul/Core/src/Core.php index 19fa1ba7b..e8120d01d 100755 --- a/packages/Webkul/Core/src/Core.php +++ b/packages/Webkul/Core/src/Core.php @@ -1047,4 +1047,38 @@ class Core { return str_replace('.', '_', (string)$taxRate); } + + /** + * Get Shop email sender details + * + * @return array + */ + public function getSenderEmailDetails() + { + $sender_name = core()->getConfigData('general.general.email_settings.sender_name') ? core()->getConfigData('general.general.email_settings.sender_name') : config('mail.from.name'); + + $sender_email = core()->getConfigData('general.general.email_settings.shop_email_from') ? core()->getConfigData('general.general.email_settings.shop_email_from') : config('mail.from.address'); + + return [ + 'name' => $sender_name, + 'email' => $sender_email, + ]; + } + + /** + * Get Admin email details + * + * @return array + */ + public function getAdminEmailDetails() + { + $admin_name = core()->getConfigData('general.general.email_settings.admin_name') ? core()->getConfigData('general.general.email_settings.admin_name') : config('mail.admin.name'); + + $admin_email = core()->getConfigData('general.general.email_settings.admin_email') ? core()->getConfigData('general.general.email_settings.admin_email') : config('mail.admin.address'); + + return [ + 'name' => $admin_name, + 'email' => $admin_email, + ]; + } } \ No newline at end of file diff --git a/packages/Webkul/Customer/src/Mail/RegistrationEmail.php b/packages/Webkul/Customer/src/Mail/RegistrationEmail.php index cc09ba9b6..49892346d 100644 --- a/packages/Webkul/Customer/src/Mail/RegistrationEmail.php +++ b/packages/Webkul/Customer/src/Mail/RegistrationEmail.php @@ -34,8 +34,9 @@ class RegistrationEmail extends Mailable */ public function build() { - return $this->to($this->data['email']) - ->subject(trans('shop::app.mail.customer.registration.customer-registration')) - ->view('shop::emails.customer.registration')->with('data', $this->data); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($this->data['email']) + ->subject(trans('shop::app.mail.customer.registration.customer-registration')) + ->view('shop::emails.customer.registration')->with('data', $this->data); } } \ No newline at end of file diff --git a/packages/Webkul/Customer/src/Mail/VerificationEmail.php b/packages/Webkul/Customer/src/Mail/VerificationEmail.php index fafe7f514..0e27a3ca6 100755 --- a/packages/Webkul/Customer/src/Mail/VerificationEmail.php +++ b/packages/Webkul/Customer/src/Mail/VerificationEmail.php @@ -34,13 +34,14 @@ class VerificationEmail extends Mailable */ public function build() { - return $this->to($this->verificationData['email']) - ->subject(trans('shop::app.mail.customer.verification.subject')) - ->view('shop::emails.customer.verification-email') - ->with('data', [ - 'email' => $this->verificationData['email'], - 'token' => $this->verificationData['token'], - ] - ); + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($this->verificationData['email']) + ->subject(trans('shop::app.mail.customer.verification.subject')) + ->view('shop::emails.customer.verification-email') + ->with('data', [ + 'email' => $this->verificationData['email'], + 'token' => $this->verificationData['token'], + ] + ); } } \ No newline at end of file diff --git a/packages/Webkul/Customer/src/Notifications/CustomerResetPassword.php b/packages/Webkul/Customer/src/Notifications/CustomerResetPassword.php index 0b8234d98..06025baeb 100755 --- a/packages/Webkul/Customer/src/Notifications/CustomerResetPassword.php +++ b/packages/Webkul/Customer/src/Notifications/CustomerResetPassword.php @@ -21,10 +21,11 @@ class CustomerResetPassword extends ResetPassword } return (new MailMessage) + ->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) ->subject(__('shop::app.mail.forget-password.subject') ) ->view('shop::emails.customer.forget-password', [ - 'user_name' => $notifiable->name, - 'token' => $this->token, + 'user_name' => $notifiable->name, + 'token' => $this->token, ] ); } diff --git a/packages/Webkul/Shop/src/Mail/SubscriptionEmail.php b/packages/Webkul/Shop/src/Mail/SubscriptionEmail.php index aac65baf9..6f791d241 100755 --- a/packages/Webkul/Shop/src/Mail/SubscriptionEmail.php +++ b/packages/Webkul/Shop/src/Mail/SubscriptionEmail.php @@ -30,14 +30,14 @@ class SubscriptionEmail extends Mailable */ public function build() { - return $this->to($this->subscriptionData['email']) - ->subject(trans('shop::app.mail.customer.subscription.subject')) - ->view('shop::emails.customer.subscription-email') - ->with('data', [ - 'content' => 'You Are Subscribed', - 'token' => $this->subscriptionData['token'], - ] - ); - + return $this->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) + ->to($this->subscriptionData['email']) + ->subject(trans('shop::app.mail.customer.subscription.subject')) + ->view('shop::emails.customer.subscription-email') + ->with('data', [ + 'content' => 'You Are Subscribed', + 'token' => $this->subscriptionData['token'], + ] + ); } } \ No newline at end of file diff --git a/packages/Webkul/User/src/Notifications/AdminResetPassword.php b/packages/Webkul/User/src/Notifications/AdminResetPassword.php index 131c5e29e..60ac1e24f 100755 --- a/packages/Webkul/User/src/Notifications/AdminResetPassword.php +++ b/packages/Webkul/User/src/Notifications/AdminResetPassword.php @@ -20,6 +20,7 @@ class AdminResetPassword extends ResetPassword } return (new MailMessage) + ->from(core()->getSenderEmailDetails()['email'], core()->getSenderEmailDetails()['name']) ->view('shop::emails.admin.forget-password', [ 'user_name' => $notifiable->name, 'token' => $this->token,