├── .github
└── FUNDING.yml
├── Block
└── Adminhtml
│ └── Email
│ └── Edit.php
├── Controller
└── Adminhtml
│ └── Edit
│ └── Index.php
├── Helper
└── Data.php
├── README.md
├── composer.json
├── etc
├── acl.xml
├── adminhtml
│ ├── routes.xml
│ └── system.xml
└── module.xml
├── i18n
└── en_US.csv
├── registration.php
└── view
└── adminhtml
├── layout
└── sales_order_view.xml
├── requirejs-config.js
├── templates
└── email.phtml
└── web
├── css
└── email-popup.less
└── js
└── email.js
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | #github: [srenon]
4 | custom: ['https://paypal.me/magepal']
5 |
--------------------------------------------------------------------------------
/Block/Adminhtml/Email/Edit.php:
--------------------------------------------------------------------------------
1 | coreRegistry = $coreRegistry;
62 | $this->authorization = $authorization;
63 | $this->_helper = $helper;
64 | }
65 |
66 | /**
67 | * @return string
68 | */
69 | public function getAdminPostUrl()
70 | {
71 | return $this->getUrl('editorderemail/edit/index');
72 | }
73 |
74 | /**
75 | * @return int
76 | */
77 | public function getOrderId()
78 | {
79 | return $this->getRequest()->getParam('order_id');
80 | }
81 |
82 | public function getOrder()
83 | {
84 | return $this->coreRegistry->registry('sales_order');
85 | }
86 |
87 | /**
88 | * @return int
89 | */
90 | public function getAutocheckEmail()
91 | {
92 | return $this->_helper->isSetFlag('general/update_customer_email') ? 1 : 0;
93 | }
94 |
95 | /**
96 | * @return string
97 | */
98 | public function getEmailAddress()
99 | {
100 | /** @var OrderInterface $order */
101 | if ($order = $this->getOrder()) {
102 | return $order->getCustomerEmail();
103 | }
104 |
105 | return '';
106 | }
107 |
108 | /**
109 | * @return bool
110 | */
111 | public function hasCustomerId()
112 | {
113 | /** @var OrderInterface $order */
114 | if ($order = $this->getOrder()) {
115 | return $order->getCustomerId() ? true : false;
116 | }
117 |
118 | return false;
119 | }
120 |
121 | /**
122 | * @return string
123 | */
124 | protected function _toHtml()
125 | {
126 | if (!$this->_authorization->isAllowed('MagePal_EditOrderEmail::magepal_editorderemail')) {
127 | return '';
128 | }
129 |
130 | return parent::_toHtml();
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/Controller/Adminhtml/Edit/Index.php:
--------------------------------------------------------------------------------
1 | orderRepository = $orderRepository;
84 | $this->orderCustomerService = $orderCustomerService;
85 | $this->resultJsonFactory = $resultJsonFactory;
86 | $this->accountManagement = $accountManagement;
87 | $this->customerRepository = $customerRepository;
88 | $this->emailAddressValidator = $emailAddressValidator;
89 | $this->authSession = $authSession;
90 | }
91 |
92 | /**
93 | * Index action
94 | * @return Json
95 | * @throws Exception
96 | */
97 | public function execute()
98 | {
99 | $request = $this->getRequest();
100 | $orderId = $request->getPost('order_id');
101 | $emailAddress = trim($request->getPost('email'));
102 | $oldEmailAddress = $request->getPost('old_email');
103 | $updateCustomerEmailRecord = $request->getPost('update_customer_email');
104 | $resultJson = $this->resultJsonFactory->create();
105 |
106 | if (!isset($orderId)) {
107 | return $resultJson->setData(
108 | [
109 | 'error' => true,
110 | 'message' => __('Invalid order id.'),
111 | 'email' => '',
112 | 'ajaxExpired' => false
113 | ]
114 | );
115 | }
116 |
117 | if (!$this->emailAddressValidator->isValid($emailAddress)) {
118 | return $resultJson->setData(
119 | [
120 | 'error' => true,
121 | 'message' => __('Invalid Email address.'),
122 | 'email' => '',
123 | 'ajaxExpired' => false
124 | ]
125 | );
126 | }
127 |
128 | try {
129 | /** @var $order OrderInterface */
130 | $order = $this->orderRepository->get($orderId);
131 | if ($order->getEntityId() && $order->getCustomerEmail() == $oldEmailAddress) {
132 | $comment = sprintf(
133 | __("Order email address change from %s to %s by %s"),
134 | $oldEmailAddress,
135 | $emailAddress,
136 | $this->authSession->getUser()->getUserName()
137 | );
138 |
139 | $order->addStatusHistoryComment($comment);
140 | $order->setCustomerEmail($emailAddress);
141 | $this->orderRepository->save($order);
142 |
143 | foreach ($order->getAddressesCollection() as $address)
144 | {
145 | $address->setEmail($emailAddress)->save();
146 | }
147 | }
148 |
149 | //if update customer email
150 | if ($updateCustomerEmailRecord == 1
151 | && $order->getCustomerId()
152 | && $this->accountManagement->isEmailAvailable($emailAddress)
153 | ) {
154 | $customer = $this->customerRepository->getById($order->getCustomerId());
155 | if ($customer->getId()) {
156 | $customer->setEmail($emailAddress);
157 | $this->customerRepository->save($customer);
158 | }
159 | }
160 |
161 | return $resultJson->setData(
162 | [
163 | 'error' => false,
164 | 'message' => __('Email address successfully changed.'),
165 | 'email' => $emailAddress,
166 | 'ajaxExpired' => false
167 | ]
168 | );
169 | } catch (Exception $e) {
170 | return $resultJson->setData(
171 | [
172 | 'error' => true,
173 | 'message' => $e->getMessage(),
174 | 'email' => '',
175 | 'ajaxExpired' => false
176 | ]
177 | );
178 | }
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/Helper/Data.php:
--------------------------------------------------------------------------------
1 | scopeConfig->isSetFlag(
23 | 'magepal_editorderemail/' . $configPath,
24 | ScopeInterface::SCOPE_STORE
25 | );
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Magento2 - Edit Order Email Address
4 |
5 | [](https://www.magepal.com/magento2/extensions/edit-order-email-address-for-magento-2.html)
6 | [](https://www.magepal.com/magento2/extensions/edit-order-email-address-for-magento-2.html)
7 | [](https://www.magepal.com/magento2/extensions/edit-order-email-address-for-magento-2.html)
8 | [](https://www.magepal.com/magento2/extensions/edit-order-email-address-for-magento-2.html)
9 |
10 |
11 |
12 |
13 | Entering the wrong email address during purchase is a very common mistake, especially on order by phone transactions. Reduce the number of hours and frustration each time a customer mistype their email. With our extension the is no need to cancel and reorder just to correct a simple email in an email address.
14 |
15 |
16 |
17 | ## Features
18 | - Edit order email address.
19 | - Update order customer email address (optional).
20 | - Add order email change history to order comment along with the admin user who changes the email address.
21 |
22 | ## Documentation
23 |
24 | - [How to Install Edit Order Email for Magento](https://www.magepal.com/help/docs/edit-order-email-magento2/#installation)
25 |
26 | - [How to setup Edit Order Email for Magento 2](https://www.magepal.com/help/docs/edit-order-email-magento2/#configuration)
27 |
28 |
29 | ## Installation
30 |
31 | ##### Using Composer
32 | ```
33 | composer require magepal/magento2-edit-order-email
34 | ```
35 |
36 |
37 |
38 |
39 |
40 | Contribution
41 | ---
42 | Want to contribute to this extension? The quickest way is to open a [pull request on GitHub](https://help.github.com/articles/using-pull-requests).
43 |
44 |
45 | Support
46 | ---
47 | If you encounter any problems or bugs, please open an issue on [GitHub](https://github.com/magepal/magento2-edit-order-email/issues).
48 |
49 | Need help setting up or want to customize this extension to meet your business needs? Please email support@magepal.com and if we like your idea we will add this feature for free or at a discounted rate.
50 |
51 |
52 | Magento 2 Extensions
53 | ---
54 | - [Custom SMTP](https://www.magepal.com/magento2/extensions/custom-smtp.html)
55 | - [Catalog Hover Image for Magento](https://www.magepal.com/magento2/extensions/catalog-hover-image-for-magento.html)
56 | - [Enhanced Success Page for Magento 2](https://www.magepal.com/magento2/extensions/enhanced-success-page.html)
57 | - [Enhanced Transactional Emails for Magento 2](https://www.magepal.com/magento2/extensions/enhanced-transactional-emails.html)
58 | - [Google Tag Manager](https://www.magepal.com/magento2/extensions/google-tag-manager.html)
59 | - [Enhanced E-commerce](https://www.magepal.com/magento2/extensions/enhanced-ecommerce-for-google-tag-manager.html)
60 | - [Reindex](https://www.magepal.com/magento2/extensions/reindex.html)
61 | - [Custom Shipping Method](https://www.magepal.com/magento2/extensions/custom-shipping-rates-for-magento-2.html)
62 | - [Preview Order Confirmation](https://www.magepal.com/magento2/extensions/preview-order-confirmation-page-for-magento-2.html)
63 | - [Guest to Customer](https://www.magepal.com/magento2/extensions/guest-to-customer.html)
64 | - [Admin Form Fields Manager](https://www.magepal.com/magento2/extensions/admin-form-fields-manager-for-magento-2.html)
65 | - [Customer Dashboard Links Manager](https://www.magepal.com/magento2/extensions/customer-dashboard-links-manager-for-magento-2.html)
66 | - [Lazy Loader](https://www.magepal.com/magento2/extensions/lazy-load.html)
67 | - [Order Confirmation Page Miscellaneous Scripts](https://www.magepal.com/magento2/extensions/order-confirmation-miscellaneous-scripts-for-magento-2.html)
68 | - [HTML Minifier for Magento2](https://www.magepal.com/magento2/extensions/html-minifier.html)
69 |
70 | © MagePal LLC. | [www.magepal.com](https://www.magepal.com)
71 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "magepal/magento2-edit-order-email",
3 | "description":"Magento 2 edit order email",
4 | "keywords": [
5 | "magento 2",
6 | "edit order email",
7 | "change order email",
8 | "how to change order email",
9 | "change email address",
10 | "wrong order email"
11 | ],
12 | "require": {
13 | "php": "~7.2.0|~7.3.0|~7.4.0|~8.1.0|~8.2.0|~8.3.0|~8.4.0",
14 | "magento/module-backend": "100.0.*|100.1.*|100.2.*|101.0.*|102.0.*",
15 | "magento/framework": "100.0.*|100.1.*|101.0.*|102.0.*|103.0.*",
16 | "magepal/magento2-core": ">=1.1.10"
17 | },
18 | "type": "magento2-module",
19 | "version": "1.1.10",
20 | "license": [
21 | "proprietary"
22 | ],
23 | "homepage": "https://www.magepal.com/",
24 | "support": {
25 | "email": "support@magepal.com",
26 | "issues": "https://github.com/magepal/magento2-edit-order-email/issues/"
27 | },
28 | "authors": [
29 | {
30 | "name": "Renon Stewart",
31 | "email": "renon@magepal.com",
32 | "homepage": "https://www.magepal.com/",
33 | "role": "Leader"
34 | }
35 | ],
36 | "autoload": {
37 | "files": [
38 | "registration.php"
39 | ],
40 | "psr-4": {
41 | "MagePal\\EditOrderEmail\\": ""
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/etc/acl.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
34 | ]]>
35 |