├── .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 | [![Total Downloads](https://poser.pugx.org/magepal/magento2-edit-order-email/downloads)](https://www.magepal.com/magento2/extensions/edit-order-email-address-for-magento-2.html) 6 | [![Latest Stable Version](https://poser.pugx.org/magepal/magento2-edit-order-email/v/stable)](https://www.magepal.com/magento2/extensions/edit-order-email-address-for-magento-2.html) 7 | [![GitHub stars](https://img.shields.io/github/stars/magepal/magento2-edit-order-email.svg)](https://www.magepal.com/magento2/extensions/edit-order-email-address-for-magento-2.html) 8 | [![GitHub forks](https://img.shields.io/github/forks/magepal/magento2-edit-order-email.svg)](https://www.magepal.com/magento2/extensions/edit-order-email-address-for-magento-2.html) 9 | 10 | Magento2 - Edit Order Email 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 | Magento2 - Edit Order Email 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 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /etc/adminhtml/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | magepal 17 | MagePal_EditOrderEmail::magepal_editorderemail 18 | 19 | 1 20 | 21 | 23 | Copyright © 2024 MagePal, LLC 24 | Documentation 25 | Support 26 | Latest Version 27 | Extension Detail 28 | More Extensions 29 | 30 | Automatically convert guest checkout to customer with our 31 | 32 | Guest to Customer extension. 33 |
34 | ]]> 35 |
36 | 37 | 38 | MagePal\Core\Block\Adminhtml\System\Config\Composer\Version 39 | 40 |
41 | 42 | 43 | 44 | Magento\Config\Model\Config\Source\Yesno 45 | 46 | 47 |
48 |
49 |
50 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /i18n/en_US.csv: -------------------------------------------------------------------------------- 1 | "Module Version","Module Version" 2 | "Composer Version","Composer Version" 3 | "CUSTOM SHIPPING RATE","CUSTOM SHIPPING RATE" 4 | "Enable","Enable" 5 | "Invalid order id.","Invalid order id." 6 | "Invalid Email address.","Invalid Email address." 7 | "Order email address change from %s to %s by %s","Order email address change from %s to %s by %s" 8 | "Email address successfully changed.","Email address successfully changed." 9 | "Automatically update customer record email address","Automatically update customer record email address" -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /view/adminhtml/requirejs-config.js: -------------------------------------------------------------------------------- 1 | var config = { 2 | map: { 3 | '*': { 4 | magePalEditOrderEmail: 'MagePal_EditOrderEmail/js/email' 5 | } 6 | } 7 | }; -------------------------------------------------------------------------------- /view/adminhtml/templates/email.phtml: -------------------------------------------------------------------------------- 1 | 10 | 44 | 45 | 55 | -------------------------------------------------------------------------------- /view/adminhtml/web/css/email-popup.less: -------------------------------------------------------------------------------- 1 | #mpEditOrderEmailPopup{ 2 | margin-left: 10px; 3 | } 4 | 5 | #mp_edit_order_email{ 6 | width: 400px; 7 | padding-bottom: 30px; 8 | 9 | .actions { 10 | margin-top: 10px; 11 | } 12 | 13 | .msg { 14 | margin-top: 10px; 15 | } 16 | } -------------------------------------------------------------------------------- /view/adminhtml/web/js/email.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © MagePal LLC. All rights reserved. 3 | * See COPYING.txt for license details. 4 | * https://www.magepal.com | support@magepal.com 5 | */ 6 | 7 | define([ 8 | 'Magento_Ui/js/modal/modal', 9 | 'jquery', 10 | 'mage/translate' 11 | ], function (alert, $, $t) { 12 | 'use strict'; 13 | 14 | var emailModal; 15 | var $form = $('form.change-order-email'); 16 | var $emailHref = $('table.order-account-information-table tr a[href^="mailto:"]'); 17 | 18 | var mpEditOrderEmailPopup = function () { 19 | if (!emailModal) { 20 | emailModal = $('#mp_edit_order_email').modal({ 21 | title: 'Edit Email', 22 | content: 'Warning content', 23 | buttons: [] 24 | }); 25 | } 26 | 27 | emailModal.modal('openModal'); 28 | }; 29 | 30 | var mpSaveNewEmailFormPost = function ( postUrl ) { 31 | 32 | 33 | if ($form.valid()) { 34 | var url = $form.attr('action'); 35 | var postData = $form.serializeArray(); 36 | postData.push({form_key : FORM_KEY}); 37 | 38 | try { 39 | $.ajax({ 40 | url: url, 41 | dataType: 'json', 42 | type: 'POST', 43 | showLoader: true, 44 | data: $.param(postData), 45 | complete: function (data) { 46 | if (typeof data === 'object') { 47 | data = data.responseJSON; 48 | if (data.error === false) { 49 | setTimeout(function () { 50 | emailModal.modal('closeModal'); 51 | },10000); 52 | 53 | if (data.email) { 54 | $emailHref.attr("href", "mailto:" + data.email).text(data.email); 55 | $('#mp_edit_order_email input[name="old_email"]').val(data.email); 56 | } 57 | } 58 | 59 | if (data.ajaxExpired) { 60 | window.location.href = data.ajaxRedirect; 61 | } 62 | 63 | $(".mage-error").html(data.message); 64 | } else { 65 | $(".mage-error").html($t('Unknown Error')); 66 | } 67 | 68 | return false; 69 | } 70 | }); 71 | } catch (e) { 72 | $(".mage-error").html(e.message); 73 | } 74 | } else { 75 | $("div.menu-wrapper._fixed").removeAttr("style"); 76 | } 77 | 78 | return false; 79 | 80 | }; 81 | 82 | return function (config) { 83 | var html = ''; 84 | $emailHref.parent().append(html); 85 | 86 | $('#mpEditOrderEmailPopup').click(function () { 87 | mpEditOrderEmailPopup(); 88 | }); 89 | 90 | $('form.change-order-email button').on('click', function () { 91 | mpSaveNewEmailFormPost(config.postUrl); 92 | }); 93 | 94 | $form.on("keypress", function (event) { 95 | if (event.keyCode === 13) { 96 | mpSaveNewEmailFormPost(config.postUrl); 97 | } 98 | 99 | return event.keyCode != 13; 100 | }); 101 | 102 | $form.submit(function (event) { 103 | return false; 104 | }); 105 | } 106 | }); 107 | --------------------------------------------------------------------------------