How to override default contact form Model file in Magento 2.2.5?main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelWhy Getting categories and names on product view page Magento 2 fails?Magento Contact Form: Unable to submit your request. Please, try again laterMagento 2: Plugin class does not existMagento offline custom Payment method with drop down listMagento 2 : override model fileHow to solve Front controller reached 100 router match iterations in magento2Magento 2.3 Can't view module's front end page output?Magento 2.3.0 - Set up multiple websites, stores, and store views
Violin - Can double stops be played when the strings are not next to each other?
Co-worker team leader wants to inject his friend's awful software into our development. What should I say to our common boss?
What are substitutions for coconut in curry?
Python if-else code style for reduced code for rounding floats
What is "focus distance lower/upper" and how is it different from depth of field?
What's wrong with this fake proof of Twin Prime Conjecture?
Why would a flight no longer considered airworthy be redirected like this?
My adviser wants to be the first author
how to write formula in word in latex
How to change two letters closest to a string and one letter immediately after a string using notepad++
Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?
Is it insecure to send a password in a `curl` command?
How to write a general formula for this sequence?
How to terminate ping <dest> &
A sequence that has integer values for prime indexes only
Did Ender ever learn that he killed Stilson and/or Bonzo?
How to parse string to number while destructuring?
What is the significance behind "40 days" that often appears in the Bible?
Why is the President allowed to veto a cancellation of emergency powers?
How Could an Airship Be Repaired Mid-Flight
How can I get full line of circle of this picture?
I got the following comment from a reputed math journal. What does it mean?
Is "upgrade" the right word to use in this context?
How many ways can 200 identical balls be distributed into 40 distinct jars?
How to override default contact form Model file in Magento 2.2.5?
main.CRITICAL: Plugin class doesn't existMagento 2: How to override newsletter Subscriber modelWhy Getting categories and names on product view page Magento 2 fails?Magento Contact Form: Unable to submit your request. Please, try again laterMagento 2: Plugin class does not existMagento offline custom Payment method with drop down listMagento 2 : override model fileHow to solve Front controller reached 100 router match iterations in magento2Magento 2.3 Can't view module's front end page output?Magento 2.3.0 - Set up multiple websites, stores, and store views
I want to override default contact form Model file (ie, Mail.php and mailinterface.php) in Magento 2.
Struggling to override this file since the last 2days.
Any help would be appreciated.
/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
class Mail extends MailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)
/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list
$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
finally
$this->inlineTranslation->resume();
/var/www/html/magento/app/code/Amy/Contactform/Model/Mail1Interface.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
/**
* Email from contact form
*
* @api
* @since 100.2.0
*/
interface Mail1Interface extends MialInterface
/**
* Send email from contact form
*
* @param string $replyTo Reply-to email address
* @param array $variables Email template variables
* @return void
* @since 100.2.0
*/
public function send($recipient, $replyTo, array $variables);
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformControllerIndex;
use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
class Post extends MagentoContactControllerIndexPost
/**
* @var DataPersistorInterface
*/
private $dataPersistor;
/**
* @var Context
*/
private $context;
/**
* @var MailInterface
*/
private $mail;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
/**
* Post user question
*
* @return Redirect
*/
public function execute()
if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');
try
$this->sendEmail($this->validatedParams());
$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
return $this->resultRedirectFactory->create()->setPath('contact/index');
/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)
$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);
/**
* @return bool
*/
private function isPostRequest()
/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());
/**
* @return array
* @throws Exception
*/
private function validatedParams()
$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));
if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));
if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));
if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));
if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));
if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));
if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));
if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));
if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));
if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));
if (trim($request->getParam('hideit')) !== '')
throw new Exception();
return $request->getParams();
/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactControllerIndexPost" type="AmyContactformControllerIndexPost" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
</config>
magento2 contact-form override-model
|
show 3 more comments
I want to override default contact form Model file (ie, Mail.php and mailinterface.php) in Magento 2.
Struggling to override this file since the last 2days.
Any help would be appreciated.
/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
class Mail extends MailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)
/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list
$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
finally
$this->inlineTranslation->resume();
/var/www/html/magento/app/code/Amy/Contactform/Model/Mail1Interface.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
/**
* Email from contact form
*
* @api
* @since 100.2.0
*/
interface Mail1Interface extends MialInterface
/**
* Send email from contact form
*
* @param string $replyTo Reply-to email address
* @param array $variables Email template variables
* @return void
* @since 100.2.0
*/
public function send($recipient, $replyTo, array $variables);
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformControllerIndex;
use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
class Post extends MagentoContactControllerIndexPost
/**
* @var DataPersistorInterface
*/
private $dataPersistor;
/**
* @var Context
*/
private $context;
/**
* @var MailInterface
*/
private $mail;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
/**
* Post user question
*
* @return Redirect
*/
public function execute()
if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');
try
$this->sendEmail($this->validatedParams());
$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
return $this->resultRedirectFactory->create()->setPath('contact/index');
/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)
$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);
/**
* @return bool
*/
private function isPostRequest()
/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());
/**
* @return array
* @throws Exception
*/
private function validatedParams()
$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));
if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));
if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));
if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));
if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));
if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));
if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));
if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));
if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));
if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));
if (trim($request->getParam('hideit')) !== '')
throw new Exception();
return $request->getParams();
/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactControllerIndexPost" type="AmyContactformControllerIndexPost" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
</config>
magento2 contact-form override-model
Tried preference if so post code here @Amy
– Prathap Gunasekaran
yesterday
what function and what you want to modify
– Amit Bera♦
yesterday
check my update question..
– Amy
yesterday
@Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.
– Prathap Gunasekaran
yesterday
Is it possible to override MailInterface.php
– Amy
yesterday
|
show 3 more comments
I want to override default contact form Model file (ie, Mail.php and mailinterface.php) in Magento 2.
Struggling to override this file since the last 2days.
Any help would be appreciated.
/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
class Mail extends MailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)
/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list
$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
finally
$this->inlineTranslation->resume();
/var/www/html/magento/app/code/Amy/Contactform/Model/Mail1Interface.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
/**
* Email from contact form
*
* @api
* @since 100.2.0
*/
interface Mail1Interface extends MialInterface
/**
* Send email from contact form
*
* @param string $replyTo Reply-to email address
* @param array $variables Email template variables
* @return void
* @since 100.2.0
*/
public function send($recipient, $replyTo, array $variables);
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformControllerIndex;
use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
class Post extends MagentoContactControllerIndexPost
/**
* @var DataPersistorInterface
*/
private $dataPersistor;
/**
* @var Context
*/
private $context;
/**
* @var MailInterface
*/
private $mail;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
/**
* Post user question
*
* @return Redirect
*/
public function execute()
if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');
try
$this->sendEmail($this->validatedParams());
$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
return $this->resultRedirectFactory->create()->setPath('contact/index');
/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)
$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);
/**
* @return bool
*/
private function isPostRequest()
/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());
/**
* @return array
* @throws Exception
*/
private function validatedParams()
$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));
if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));
if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));
if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));
if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));
if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));
if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));
if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));
if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));
if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));
if (trim($request->getParam('hideit')) !== '')
throw new Exception();
return $request->getParams();
/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactControllerIndexPost" type="AmyContactformControllerIndexPost" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
</config>
magento2 contact-form override-model
I want to override default contact form Model file (ie, Mail.php and mailinterface.php) in Magento 2.
Struggling to override this file since the last 2days.
Any help would be appreciated.
/var/www/html/magento/app/code/Amy/Contactform/Model/Mail.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
class Mail extends MailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)
/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list
$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
finally
$this->inlineTranslation->resume();
/var/www/html/magento/app/code/Amy/Contactform/Model/Mail1Interface.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
/**
* Email from contact form
*
* @api
* @since 100.2.0
*/
interface Mail1Interface extends MialInterface
/**
* Send email from contact form
*
* @param string $replyTo Reply-to email address
* @param array $variables Email template variables
* @return void
* @since 100.2.0
*/
public function send($recipient, $replyTo, array $variables);
/var/www/html/magento/app/code/Amy/Contactform/Controller/Index/Post.php
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformControllerIndex;
use MagentoContactModelConfigInterface;
use MagentoContactModelMailInterface;
use MagentoFrameworkAppActionContext;
use MagentoFrameworkAppRequestDataPersistorInterface;
use MagentoFrameworkControllerResultRedirect;
use MagentoFrameworkExceptionLocalizedException;
use MagentoFrameworkHTTPPhpEnvironmentRequest;
use PsrLogLoggerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkDataObject;
class Post extends MagentoContactControllerIndexPost
/**
* @var DataPersistorInterface
*/
private $dataPersistor;
/**
* @var Context
*/
private $context;
/**
* @var MailInterface
*/
private $mail;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @param Context $context
* @param ConfigInterface $contactsConfig
* @param MailInterface $mail
* @param DataPersistorInterface $dataPersistor
* @param LoggerInterface $logger
*/
public function __construct(
Context $context,
ConfigInterface $contactsConfig,
MailInterface $mail,
DataPersistorInterface $dataPersistor,
LoggerInterface $logger = null
)
parent::__construct($context, $contactsConfig, $mail, $dataPersistor);
$this->context = $context;
$this->mail = $mail;
$this->dataPersistor = $dataPersistor;
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
/**
* Post user question
*
* @return Redirect
*/
public function execute()
if (!$this->isPostRequest())
return $this->resultRedirectFactory->create()->setPath('*/*/');
try
$this->sendEmail($this->validatedParams());
$this->messageManager->addSuccessMessage(
__('Thanks for contacting us. Your inquiry was submitted and will be responded to you as soon as possible.')
);
$this->dataPersistor->clear('contact_us');
catch (LocalizedException $e)
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
catch (Exception $e)
$this->logger->critical($e);
$this->messageManager->addErrorMessage(
__('An error occurred while processing your form. Please try again later.')
);
$this->dataPersistor->set('contact_us', $this->getRequest()->getParams());
return $this->resultRedirectFactory->create()->setPath('contact/index');
/**
* @param array $post Post data from contact form
* @return void
*/
private function sendEmail($post)
$this->mail->send(
$post['subject'],
$post['email'],
['data' => new DataObject($post)]
);
/**
* @return bool
*/
private function isPostRequest()
/** @var Request $request */
$request = $this->getRequest();
return !empty($request->getPostValue());
/**
* @return array
* @throws Exception
*/
private function validatedParams()
$request = $this->getRequest();
if (trim($request->getParam('name')) === '')
throw new LocalizedException(__('Name is missing'));
if (trim($request->getParam('lastname')) === '')
throw new LocalizedException(__('LastName is missing'));
if (trim($request->getParam('address1')) === '')
throw new LocalizedException(__('Address1 is missing'));
if (trim($request->getParam('address2')) === '')
throw new LocalizedException(__('Address2 is missing'));
if (trim($request->getParam('city')) === '')
throw new LocalizedException(__('City is missing'));
if (trim($request->getParam('stateprovince')) === '')
throw new LocalizedException(__('State is missing'));
if (trim($request->getParam('zipcode')) === '')
throw new LocalizedException(__('Zipcode is missing'));
if (trim($request->getParam('subject')) === '')
throw new LocalizedException(__('Subject is missing'));
if (trim($request->getParam('comment')) === '')
throw new LocalizedException(__('Comment is missing'));
if (false === strpos($request->getParam('email'), '@'))
throw new LocalizedException(__('Invalid email address'));
if (trim($request->getParam('hideit')) !== '')
throw new Exception();
return $request->getParams();
/var/www/html/magento/app/code/Amy/Contactform/etc/di.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactBlockContactForm" type="AmyContactformBlockContactForm" />
<preference for="MagentoContactControllerIndexPost" type="AmyContactformControllerIndexPost" />
<preference for="MagentoContactModelMail" type="AmyContactformModelMail" />
</config>
magento2 contact-form override-model
magento2 contact-form override-model
edited yesterday
Amy
asked yesterday
AmyAmy
3029
3029
Tried preference if so post code here @Amy
– Prathap Gunasekaran
yesterday
what function and what you want to modify
– Amit Bera♦
yesterday
check my update question..
– Amy
yesterday
@Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.
– Prathap Gunasekaran
yesterday
Is it possible to override MailInterface.php
– Amy
yesterday
|
show 3 more comments
Tried preference if so post code here @Amy
– Prathap Gunasekaran
yesterday
what function and what you want to modify
– Amit Bera♦
yesterday
check my update question..
– Amy
yesterday
@Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.
– Prathap Gunasekaran
yesterday
Is it possible to override MailInterface.php
– Amy
yesterday
Tried preference if so post code here @Amy
– Prathap Gunasekaran
yesterday
Tried preference if so post code here @Amy
– Prathap Gunasekaran
yesterday
what function and what you want to modify
– Amit Bera♦
yesterday
what function and what you want to modify
– Amit Bera♦
yesterday
check my update question..
– Amy
yesterday
check my update question..
– Amy
yesterday
@Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.
– Prathap Gunasekaran
yesterday
@Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.
– Prathap Gunasekaran
yesterday
Is it possible to override MailInterface.php
– Amy
yesterday
Is it possible to override MailInterface.php
– Amy
yesterday
|
show 3 more comments
3 Answers
3
active
oldest
votes
Have you tried the preference as below :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
</config>
I have tried it, not working..
– Amy
yesterday
add a comment |
After struggling for days, I got the solution
This is how you will be able to override the contact Model Mail.php file,
I posted this answer, because it may be useful to others.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;
class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)
/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list
$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
finally
$this->inlineTranslation->resume();
add a comment |
Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :
<preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>
Thanks
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266073%2fhow-to-override-default-contact-form-model-file-in-magento-2-2-5%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Have you tried the preference as below :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
</config>
I have tried it, not working..
– Amy
yesterday
add a comment |
Have you tried the preference as below :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
</config>
I have tried it, not working..
– Amy
yesterday
add a comment |
Have you tried the preference as below :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
</config>
Have you tried the preference as below :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoContactModelMail" type="VendorNameModuleNameModelMail" />
</config>
edited yesterday
answered yesterday
Amit NaraniwalAmit Naraniwal
911411
911411
I have tried it, not working..
– Amy
yesterday
add a comment |
I have tried it, not working..
– Amy
yesterday
I have tried it, not working..
– Amy
yesterday
I have tried it, not working..
– Amy
yesterday
add a comment |
After struggling for days, I got the solution
This is how you will be able to override the contact Model Mail.php file,
I posted this answer, because it may be useful to others.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;
class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)
/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list
$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
finally
$this->inlineTranslation->resume();
add a comment |
After struggling for days, I got the solution
This is how you will be able to override the contact Model Mail.php file,
I posted this answer, because it may be useful to others.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;
class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)
/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list
$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
finally
$this->inlineTranslation->resume();
add a comment |
After struggling for days, I got the solution
This is how you will be able to override the contact Model Mail.php file,
I posted this answer, because it may be useful to others.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;
class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)
/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list
$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
finally
$this->inlineTranslation->resume();
After struggling for days, I got the solution
This is how you will be able to override the contact Model Mail.php file,
I posted this answer, because it may be useful to others.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace AmyContactformModel;
use MagentoFrameworkMailTemplateTransportBuilder;
use MagentoFrameworkTranslateInlineStateInterface;
use MagentoStoreModelStoreManagerInterface;
use MagentoFrameworkAppObjectManager;
use MagentoFrameworkAppArea;
use MagentoContactModelConfigInterface;
class Mail extends MagentoContactModelMail implements MagentoContactModelMailInterface
null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
)
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
/**
* Send email from contact form
*
* @param string $replyTo
* @param array $variables
* @return void
*/
public function send($recipient, $replyTo, array $variables)
/** @see MagentoContactControllerIndexPost::validatedParams() */
$replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;
if ($recipient == 'General feedback')
$emails = ['aaa@gmail.com']; // add your email list
else if ($recipient == 'Warranty')
$emails = ['bbb@gmail.com']; // add your email list
$this->inlineTranslation->suspend();
try
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($emails)
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
finally
$this->inlineTranslation->resume();
answered 4 hours ago
AmyAmy
3029
3029
add a comment |
add a comment |
Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :
<preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>
Thanks
add a comment |
Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :
<preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>
Thanks
add a comment |
Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :
<preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>
Thanks
Mailinterface.php model is an interface class and we can't directly override magento's core interfaces. You can override Mail.php using preference like :
<preference for="MagentoContactModelMail" type="NamespaceModulenameModelMailOverride"/>
Thanks
answered yesterday
Hardik PatelHardik Patel
505314
505314
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266073%2fhow-to-override-default-contact-form-model-file-in-magento-2-2-5%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Tried preference if so post code here @Amy
– Prathap Gunasekaran
yesterday
what function and what you want to modify
– Amit Bera♦
yesterday
check my update question..
– Amy
yesterday
@Amy Is any one of it working, if not go for <plugin> method to override each function with around method. I could see that you're overriding three functions in each class so better go for plugin to achieve it.
– Prathap Gunasekaran
yesterday
Is it possible to override MailInterface.php
– Amy
yesterday