If you want to send transnational emails for another cc mail to the customer, then follow below steps.
Step 1: Create a registration file like Magemonkey/EmailCC/registration.php
1 2 3 4 5 6 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magemonkey_EmailCC', __DIR__ ); |
Step 2: Create di file like Magemonkey/EmailCC/etc/di.xml
1 2 3 4 5 6 |
<?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Framework\Mail\Template\TransportBuilder"> <plugin disabled="false" name="Magemonkey_EmailCC_Plugin_Magento_Framework_Mail_Template_TransportBuilder" sortOrder="10" type="Magemonkey\EmailCC\Plugin\Magento\Framework\Mail\Template\TransportBuilder"/> </type> </config> |
Step 3: Create module file like Magemonkey/EmailCC/etc/module.xml
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Magemonkey_EmailCC" setup_version="1.1.0"> <sequence> <module name="Magento_Customer"/> <module name="Magento_Framework"/> </sequence> </module> </config> |
Step 4: Create extension attributes file like Magemonkey/EmailCC/etc/extension_attributes.xml
1 2 3 4 5 6 |
<?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd"> <extension_attributes for="Magento\Customer\Api\Data\CustomerInterface"> <attribute code="mm_emailcc" type="string"/> </extension_attributes> </config> |
Step 5: Create plugin file like Magemonkey/EmailCC/Plugin/Magento/Framework/Mail/Template/TransportBuilder.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
<?php namespace Magemonkey\EmailCC\Plugin\Magento\Framework\Mail\Template; /** * Plugin to add customer email cc */ class TransportBuilder { /** * @var \Magento\Customer\Api\CustomerRepositoryInterface */ protected $customerRepositoryInterface; /** * @var \Magento\Customer\Model\Session */ protected $customerSession; /** * @var \Psr\Log\LoggerInterface */ protected $logger; public function __construct( \Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface, \Magento\Customer\Model\Session $customerSession, \Psr\Log\LoggerInterface $logger ) { $this->customerRepositoryInterface = $customerRepositoryInterface; $this->customerSession = $customerSession; $this->logger = $logger; } public function beforeGetTransport( \Magento\Framework\Mail\Template\TransportBuilder $subject ) { try { $ccEmailAddresses = $this->getEmailCopyTo(); if (!empty($ccEmailAddresses)) { foreach ($ccEmailAddresses as $ccEmailAddress) { $subject->addCc(trim($ccEmailAddress)); $this->logger->debug((string) __('Added customer CC: %1', trim($ccEmailAddress))); } } } catch (\Exception $e) { $this->logger->error((string) __('Failure to add customer CC: %1', $e->getMessage())); } return []; } /** * Get customer id from session */ public function getCustomerIdFromSession() { if ($customer = $this->customerSession->getCustomer()) { return $customer->getId(); } return null; } /** * Return email copy_to list * @return array|bool */ public function getEmailCopyTo() { $customerId = $this->getCustomerIdFromSession(); if (!$customerId) { return false; } $customer = $this->getCustomerById($customerId); if (!$customer) { return false; } $emailCc = $customer->getCustomAttribute('mm_emailcc'); $customerEmailCC = $emailCc ? $emailCc->getValue() : null; if (!empty($customerEmailCC)) { return explode(',', trim($customerEmailCC)); } return false; } /** * Get customer by Id. * @param int $customerId * @return \Magento\Customer\Model\Data\Customer */ public function getCustomerById($customerId) { try { return $this->customerRepositoryInterface->getById($customerId); } catch (\Exception $e) { $this->logger->critical($e); return false; } } } |
Step 6: Create a setup file like Magemonkey/EmailCC/Setup/Patch/Data/AddEmailCcCustomerAttribute.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
<?php declare(strict_types=1); namespace Magemonkey\EmailCC\Setup\Patch\Data; use Magento\Customer\Model\Customer; use Magento\Customer\Setup\CustomerSetup; use Magento\Customer\Setup\CustomerSetupFactory; use Magento\Eav\Model\Entity\Attribute\Set; use Magento\Eav\Model\Entity\Attribute\SetFactory; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchRevertableInterface; class AddEmailCcCustomerAttribute implements DataPatchInterface, PatchRevertableInterface { /** * @var ModuleDataSetupInterface */ private $moduleDataSetup; /** * @var CustomerSetup */ private $customerSetupFactory; /** * @var SetFactory */ private $attributeSetFactory; /** * Constructor * * @param ModuleDataSetupInterface $moduleDataSetup * @param CustomerSetupFactory $customerSetupFactory * @param SetFactory $attributeSetFactory */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, CustomerSetupFactory $customerSetupFactory, SetFactory $attributeSetFactory ) { $this->moduleDataSetup = $moduleDataSetup; $this->customerSetupFactory = $customerSetupFactory; $this->attributeSetFactory = $attributeSetFactory; } /** * {@inheritdoc} */ public function apply() { $this->moduleDataSetup->getConnection()->startSetup(); /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); $customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY); $attributeSetId = $customerEntity->getDefaultAttributeSetId(); /** @var $attributeSet Set */ $attributeSet = $this->attributeSetFactory->create(); $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); $customerSetup->addAttribute( Customer::ENTITY, 'mm_emailcc', [ 'type' => 'varchar', 'label' => 'Email CC', 'input' => 'text', 'source' => '', 'required' => false, 'visible' => true, 'position' => 500, 'system' => false, 'backend' => '', 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => false, 'note' => __("Comma separated"), ] ); $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mm_emailcc'); $attribute->addData([ 'used_in_forms' => [ 'adminhtml_customer', 'adminhtml_checkout', 'customer_account_create', 'customer_account_edit' ] ]); $attribute->addData([ 'attribute_set_id' => $attributeSetId, 'attribute_group_id' => $attributeGroupId ]); $attribute->save(); $this->moduleDataSetup->getConnection()->endSetup(); } public function revert() { $this->moduleDataSetup->getConnection()->startSetup(); /** @var CustomerSetup $customerSetup */ $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); $customerSetup->removeAttribute(Customer::ENTITY, 'mm_emailcc'); $this->moduleDataSetup->getConnection()->endSetup(); } /** * {@inheritdoc} */ public function getAliases() { return []; } /** * {@inheritdoc} */ public static function getDependencies() { return []; } } |
Step 7: Create layout file like Magemonkey/EmailCC/view/frontend/layout/customer_account_edit.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <update handle="customer_account"/> <body> <referenceContainer name="content"> <block class="Magento\Customer\Block\Form\Edit" name="customer_edit" template="Magento_Customer::form/edit.phtml" cacheable="false"> <container name="form.additional.info" as="form_additional_info"> <block class="Magento\Customer\Block\Form\Edit" as="customer_edit_cc" name="customer.edit.css" template="Magemonkey_EmailCC::form/mm_emailcc.phtml"/> </container> </block> </referenceContainer> </body> </page> |
Step 8 : Create template file like Magemonkey/EmailCC/view/frontend/templates/form/mm_emailcc.phtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php $emailCc = $block->getCustomer()->getCustomAttribute('mm_emailcc'); $customerEmailCC = $emailCc ? $emailCc->getValue() : null; ?> <fieldset class="fieldset create account" > <legend class="legend"> <span><?=$block->escapeHtmlAttr(__('Email Copy To'))?></span> </legend> <br> <div class="field mm_emailcc"> <label for="mm_emailcc" class="label"> <span><?=$block->escapeHtmlAttr(__('Email Address (Comma separated)'));?></span> </label> <div class="control"> <input id="mm_emailcc" class="input-text" name="mm_emailcc" value="<?=$block->escapeHtmlAttr($customerEmailCC);?>" title="<?=$block->escapeHtmlAttr(__('Email Copy To'));?>" type="text" autocomplete="off" /> </div> </div> </fieldset> |
Step 9: Then after run the below commands.
1 2 3 |
php bin/magento setup:upgrade php bin/magento setup:static-content:deploy php bin/magento cache:flush |
That’s it…
Now clean cache and check “Admin > CUSTOMERS > Customers > All Customers > Edit any customer”. Your new email address cc field option should appear here in the last.
[crayon-63d3ed95e5dd8419704946/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.